-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from andinaether/feature/createNotesForDmsObject
Add createDmsObjectNotes() function in DMS SDK
- Loading branch information
Showing
4 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
packages/dms/src/dms-objects/create-dms-object-notes/create-dms-object-notes.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import {DvelopContext} from "@dvelop-sdk/core"; | ||
import { | ||
_createDmsObjectNotesDefaultTransformFunction, | ||
_createDmsObjectNotesFactory, | ||
CreateDmsObjectNotesParams | ||
} from "./create-dms-object-notes"; | ||
import {HttpResponse} from "../../utils/http"; | ||
|
||
describe("createDmsObjectNotes", () => { | ||
let mockHttpRequestFunction = jest.fn(); | ||
let mockTransformFunction = jest.fn(); | ||
|
||
let context: DvelopContext; | ||
let params: CreateDmsObjectNotesParams; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
|
||
context = { | ||
systemBaseUri: "HiItsMeSystemBaseUri" | ||
}; | ||
|
||
params = { | ||
repositoryId: "HiItsMeRepositoryId", | ||
dmsObjectId: "HiItsMeDmsObjectId", | ||
noteText: "HiItsMeNoteText" | ||
}; | ||
}); | ||
|
||
it("should make correct request", async () => { | ||
const createDmsObjectNotes = _createDmsObjectNotesFactory(mockHttpRequestFunction, mockTransformFunction); | ||
await createDmsObjectNotes(context, params); | ||
|
||
expect(mockHttpRequestFunction).toHaveBeenCalledTimes(1); | ||
expect(mockHttpRequestFunction).toHaveBeenCalledWith(context, { | ||
method: "POST", | ||
url: "/dms", | ||
follows: ["repo", "dmsobjectwithmapping", "notes"], | ||
templates: { | ||
"repositoryid": params.repositoryId, | ||
"dmsobjectid": params.dmsObjectId | ||
}, | ||
data: { | ||
"text": params.noteText | ||
} | ||
}); | ||
}); | ||
|
||
it("should pass response to transform and return transform-result", async () => { | ||
const response: HttpResponse = { data: { test: "HiItsMeTest" } } as HttpResponse; | ||
const transformResult: any = { result: "HiItsMeResult" }; | ||
mockHttpRequestFunction.mockResolvedValue(response); | ||
mockTransformFunction.mockReturnValue(transformResult); | ||
|
||
const createDmsObjectNotes = _createDmsObjectNotesFactory(mockHttpRequestFunction, mockTransformFunction); | ||
await createDmsObjectNotes(context, params); | ||
|
||
expect(mockTransformFunction).toHaveBeenCalledTimes(1); | ||
expect(mockTransformFunction).toHaveBeenCalledWith(response, context, params); | ||
}); | ||
|
||
describe("createDmsObjectNotesDefaultTransformFunction", function () { | ||
it("should map with values for all properties", async() => { | ||
const response: HttpResponse = { data: { test: "HiItsMeTest" } } as HttpResponse; | ||
mockHttpRequestFunction.mockResolvedValue(response); | ||
mockTransformFunction.mockReturnValue(params); | ||
|
||
const createDmsObjectNotes = _createDmsObjectNotesFactory(mockHttpRequestFunction, _createDmsObjectNotesDefaultTransformFunction); | ||
const result: CreateDmsObjectNotesParams = await createDmsObjectNotes(context, params); | ||
|
||
expect(result).toHaveProperty("repositoryId", params.repositoryId); | ||
expect(result).toHaveProperty("dmsObjectId", params.dmsObjectId); | ||
expect(result).toHaveProperty("noteText", params.noteText); | ||
}); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
packages/dms/src/dms-objects/create-dms-object-notes/create-dms-object-notes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import {_defaultHttpRequestFunction, HttpConfig, HttpResponse} from "../../utils/http"; | ||
import {DvelopContext} from "../../index"; | ||
|
||
/** | ||
* Parameters for the {@link createDmsObjectNotes}-function. | ||
* @category DmsObject | ||
*/ | ||
export interface CreateDmsObjectNotesParams { | ||
/** ID of the repository */ | ||
repositoryId: string; | ||
|
||
/** ID of the DmsObject */ | ||
dmsObjectId: string; | ||
|
||
/** Text for the note */ | ||
noteText: string; | ||
} | ||
|
||
/** | ||
* Default transform-function provided to the {@link createDmsObjectNotes}-function. See [Advanced Topics](https://github.com/d-velop/dvelop-sdk-node#advanced-topics) for more information. | ||
* @internal | ||
* @category DmsObject | ||
*/ | ||
export function _createDmsObjectNotesDefaultTransformFunction(response: HttpResponse<any>, _: DvelopContext, params: CreateDmsObjectNotesParams): CreateDmsObjectNotesParams { | ||
return { | ||
repositoryId: params.repositoryId, | ||
dmsObjectId: params.dmsObjectId, | ||
noteText: params.noteText | ||
}; | ||
} | ||
|
||
/** | ||
* Factory for the {@link createDmsObjectNotes}-function. See [Advanced Topics](https://github.com/d-velop/dvelop-sdk-node#advanced-topics) for more information. | ||
* @typeparam T Return type of the {@link createDmsObjectNotes}-function. A corresponding transformFunction has to be supplied. | ||
* @category DmsObject | ||
*/ | ||
export function _createDmsObjectNotesFactory<T>( | ||
httpRequestFunction: (context: DvelopContext, config: HttpConfig) => Promise<HttpResponse>, | ||
transformFunction: (response: HttpResponse, context: DvelopContext, params: CreateDmsObjectNotesParams) => T | ||
): (context: DvelopContext, params: CreateDmsObjectNotesParams) => Promise<T> { | ||
return async (context: DvelopContext, params: CreateDmsObjectNotesParams) => { | ||
const response: HttpResponse = await httpRequestFunction(context, { | ||
method: "POST", | ||
url: "/dms", | ||
follows: ["repo", "dmsobjectwithmapping", "notes"], | ||
templates: { | ||
"repositoryid": params.repositoryId, | ||
"dmsobjectid": params.dmsObjectId | ||
}, | ||
data: { | ||
"text": params.noteText | ||
} | ||
}); | ||
|
||
return transformFunction(response, context, params); | ||
}; | ||
} | ||
|
||
/** | ||
* Create a note for an existing DmsObject. | ||
* | ||
* ```typescript | ||
* import { createDmsObjectNotes } from "@dvelop-sdk/dms"; | ||
* | ||
* await createDmsObjectNotes({ | ||
* systemBaseUri: "https://steamwheedle-cartel.d-velop.cloud", | ||
* authSessionId: "dQw4w9WgXcQ" | ||
* }, { | ||
* repositoryId: "qnydFmqHuVo", | ||
* dmsObjectId: "GDYQ3PJKrT8", | ||
* noteText: "Test note" | ||
* }); | ||
* ``` | ||
* | ||
* @category DmsObject | ||
*/ | ||
/* istanbul ignore next */ | ||
export async function createDmsObjectNotes(context: DvelopContext, params: CreateDmsObjectNotesParams): Promise<CreateDmsObjectNotesParams> { | ||
return await _createDmsObjectNotesFactory(_defaultHttpRequestFunction, _createDmsObjectNotesDefaultTransformFunction)(context, params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters