-
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.
Add getDmsObjectNotes() function in DMS SDK
- Loading branch information
1 parent
c477909
commit 089029e
Showing
4 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
packages/dms/src/dms-objects/get-dms-object-notes/get-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,131 @@ | ||
import { DvelopContext } from "@dvelop-sdk/core"; | ||
import { | ||
_getDmsObjectNotesDefaultTransformFunction, | ||
_getDmsObjectNotesFactory, DmsObjectNotes, | ||
GetDmsObjectNotesParams | ||
} from "./get-dms-object-notes"; | ||
import { HttpResponse } from "../../utils/http"; | ||
|
||
describe("getDmsObjectNotes", () => { | ||
let mockHttpRequestFunction = jest.fn(); | ||
let mockTransformFunction = jest.fn(); | ||
|
||
let context: DvelopContext; | ||
let params: GetDmsObjectNotesParams; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
|
||
context = { | ||
systemBaseUri: "HiItsMeSystemBaseUri" | ||
}; | ||
|
||
params = { | ||
repositoryId: "HiItsMeRepositoryId", | ||
dmsObjectId: "HiItsMeDmsObjectId" | ||
}; | ||
}); | ||
|
||
it("should make correct request", async () => { | ||
const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, mockTransformFunction); | ||
await getDmsObjectNotes(context, params); | ||
|
||
expect(mockHttpRequestFunction).toHaveBeenCalledTimes(1); | ||
expect(mockHttpRequestFunction).toHaveBeenCalledWith(context, { | ||
method: "GET", | ||
url: "/dms", | ||
follows: ["repo", "dmsobjectwithmapping", "notes"], | ||
templates: { | ||
"repositoryid": params.repositoryId, | ||
"dmsobjectid": params.dmsObjectId | ||
} | ||
}); | ||
}); | ||
|
||
it("should pass response to transform and return transform-result", async () => { | ||
const response: HttpResponse = { data: { | ||
notes: [{ | ||
creator: { | ||
id: "HiItsMeCreatorId", | ||
displayName: "HiItsMeCreatorDisplayName" | ||
}, | ||
text: "HiItsMeText", | ||
created: "2023-10-11T09:09:09.453+02:00" | ||
}] | ||
} } as HttpResponse; | ||
|
||
const transformResult: DmsObjectNotes = { | ||
repositoryId: "HiItsMeRepositoryId", | ||
dmsObjectId: "HiItsMeDmsObjectId", | ||
notes: [{ | ||
creator: { | ||
id: "HiItsMeCreatorId", | ||
displayName: "HiItsMeCreatorDisplayName" | ||
}, | ||
text: "HiItsMeText", | ||
created: new Date("2023-10-11T09:09:09.453+02:00") | ||
}] | ||
}; | ||
|
||
mockHttpRequestFunction.mockResolvedValue(response); | ||
mockTransformFunction.mockReturnValue(transformResult); | ||
|
||
const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, mockTransformFunction); | ||
await getDmsObjectNotes(context, params); | ||
|
||
expect(mockTransformFunction).toHaveBeenCalledTimes(1); | ||
expect(mockTransformFunction).toHaveBeenCalledWith(response, context, params); | ||
}); | ||
|
||
describe("getDmsObjectNotesDefaultTransformFunction", () => { | ||
it("should return response DmsObjectNotes with single note", async () => { | ||
const response: HttpResponse = { data: { | ||
notes: [{ | ||
creator: { | ||
id: "HiItsMeCreatorId", | ||
displayName: "HiItsMeCreatorDisplayName" | ||
}, | ||
text: "HiItsMeText", | ||
created: "2023-10-11T09:09:09.453+02:00" | ||
}] | ||
} } as HttpResponse; | ||
|
||
const expectedResult: DmsObjectNotes = { | ||
repositoryId: "HiItsMeRepositoryId", | ||
dmsObjectId: "HiItsMeDmsObjectId", | ||
notes: [{ | ||
creator: { | ||
id: "HiItsMeCreatorId", | ||
displayName: "HiItsMeCreatorDisplayName" | ||
}, | ||
text: "HiItsMeText", | ||
created: new Date("2023-10-11T09:09:09.453+02:00") | ||
}] | ||
}; | ||
|
||
mockHttpRequestFunction.mockResolvedValue(response); | ||
const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, _getDmsObjectNotesDefaultTransformFunction); | ||
const result = await getDmsObjectNotes(context, params); | ||
|
||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
it("should return response DmsObjectNotes without notes when dmsObject has no notes", async () => { | ||
const response: HttpResponse = { data: { | ||
notes: [] | ||
} } as HttpResponse; | ||
|
||
const expectedResult: any = { | ||
repositoryId: "HiItsMeRepositoryId", | ||
dmsObjectId: "HiItsMeDmsObjectId", | ||
notes: [] | ||
}; | ||
|
||
mockHttpRequestFunction.mockResolvedValue(response); | ||
const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, _getDmsObjectNotesDefaultTransformFunction); | ||
const result = await getDmsObjectNotes(context, params); | ||
|
||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
120 changes: 120 additions & 0 deletions
120
packages/dms/src/dms-objects/get-dms-object-notes/get-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,120 @@ | ||
import { _defaultHttpRequestFunction, HttpConfig, HttpResponse } from "../../utils/http"; | ||
import { DvelopContext } from "../../index"; | ||
|
||
/** | ||
* Parameters for the {@link getDmsObjectNotes}-function. | ||
* @category DmsObject | ||
*/ | ||
export interface GetDmsObjectNotesParams { | ||
/** ID of the repository */ | ||
repositoryId: string; | ||
/** ID of the DmsObject */ | ||
dmsObjectId: string; | ||
} | ||
|
||
/** | ||
* Result type for the {@link getDmsObjectNotes}-function. | ||
* @category DmsObject | ||
*/ | ||
export interface DmsObjectNotes { | ||
/** ID of the repository */ | ||
repositoryId: string; | ||
/** ID of the DmsObject */ | ||
dmsObjectId: string; | ||
/* Notes of the DmsObject */ | ||
notes: SingleDmsObjectNote[]; | ||
} | ||
|
||
/** | ||
* All information provided for a single note for the {@link DmsObjectNotes}-interface. | ||
* @category DmsObject | ||
*/ | ||
export interface SingleDmsObjectNote { | ||
/* Creator of the DmsObjectNotes */ | ||
creator: { | ||
/* ID of the creator of the note */ | ||
id: string; | ||
/* DisplayName is the full name of the creator */ | ||
displayName: string; | ||
}, | ||
/* Text of the note */ | ||
text: string; | ||
/* Creation date of the note */ | ||
created: Date; | ||
} | ||
|
||
/** | ||
* Default transform-function provided to the {@link getDmsObjectNotes}-function. See [Advanced Topics](https://github.com/d-velop/dvelop-sdk-node#advanced-topics) for more information. | ||
* @internal | ||
* @category DmsObject | ||
*/ | ||
export function _getDmsObjectNotesDefaultTransformFunction(response: HttpResponse<any>, context: DvelopContext, params: GetDmsObjectNotesParams) { | ||
let responseNotes = response.data.notes; | ||
|
||
if (responseNotes === undefined || responseNotes === null) { | ||
responseNotes = []; | ||
} | ||
|
||
const mappedNotes = responseNotes.map((note: SingleDmsObjectNote) => { | ||
return { | ||
creator: { | ||
id: note.creator.id, | ||
displayName: note.creator.displayName | ||
}, | ||
text: note.text, | ||
created: new Date(note.created) | ||
}; | ||
}); | ||
|
||
return { | ||
repositoryId: params.repositoryId, | ||
dmsObjectId: params.dmsObjectId, | ||
notes: mappedNotes | ||
}; | ||
} | ||
|
||
/** | ||
* Factory for the {@link getDmsObjectNotes}-function. See [Advanced Topics](https://github.com/d-velop/dvelop-sdk-node#advanced-topics) for more information. | ||
* @typeparam T Return type of the {@link getDmsObjectNotes}-function. A corresponding transformFunction has to be supplied. | ||
* @category DmsObject | ||
*/ | ||
export function _getDmsObjectNotesFactory<T>( | ||
httpRequestFunction: (context: DvelopContext, config: HttpConfig) => Promise<HttpResponse>, | ||
transformFunction: (response: HttpResponse, context: DvelopContext, params: GetDmsObjectNotesParams) => T | ||
): (context: DvelopContext, params: GetDmsObjectNotesParams) => Promise<T> { | ||
return async (context: DvelopContext, params: GetDmsObjectNotesParams) => { | ||
const response: HttpResponse = await httpRequestFunction(context, { | ||
method: "GET", | ||
url: "/dms", | ||
follows: ["repo", "dmsobjectwithmapping", "notes"], | ||
templates: { | ||
"repositoryid": params.repositoryId, | ||
"dmsobjectid": params.dmsObjectId | ||
} | ||
}); | ||
|
||
return transformFunction(response, context, params); | ||
}; | ||
} | ||
|
||
/** | ||
* Get all notes for an existing DmsObject. | ||
* | ||
* ```typescript | ||
* import { getDmsObjectNotes } from "@dvelop-sdk/dms"; | ||
* | ||
* await createDmsObjectNote({ | ||
* systemBaseUri: "https://steamwheedle-cartel.d-velop.cloud", | ||
* authSessionId: "dQw4w9WgXcQ" | ||
* }, { | ||
* repositoryId: "qnydFmqHuVo", | ||
* dmsObjectId: "GDYQ3PJKrT8" | ||
* }); | ||
* ``` | ||
* | ||
* @category DmsObject | ||
*/ | ||
/* istanbul ignore next */ | ||
export async function getDmsObjectNotes(context: DvelopContext, params: GetDmsObjectNotesParams): Promise<DmsObjectNotes> { | ||
return await _getDmsObjectNotesFactory(_defaultHttpRequestFunction, _getDmsObjectNotesDefaultTransformFunction)(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
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