-
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 #174 from d-velop/develop
Add getDmsObjectNotes-function
- Loading branch information
Showing
8 changed files
with
290 additions
and
7 deletions.
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.
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
126 changes: 126 additions & 0 deletions
126
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,126 @@ | ||
import { DvelopContext } from "@dvelop-sdk/core"; | ||
import { | ||
_getDmsObjectNotesDefaultTransformFunction, | ||
_getDmsObjectNotesFactory, | ||
GetDmsObjectNotesParams, | ||
DmsObjectNote | ||
} 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: DmsObjectNote[] = [{ | ||
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: DmsObjectNote[] = [{ | ||
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 = []; | ||
|
||
mockHttpRequestFunction.mockResolvedValue(response); | ||
const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, _getDmsObjectNotesDefaultTransformFunction); | ||
const result = await getDmsObjectNotes(context, params); | ||
|
||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
104 changes: 104 additions & 0 deletions
104
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,104 @@ | ||
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; | ||
} | ||
|
||
/** | ||
* All information provided for a single note for the {@link DmsObjectNotes}-interface. | ||
* @category DmsObject | ||
*/ | ||
export interface DmsObjectNote { | ||
/* 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>, _: DvelopContext, __: GetDmsObjectNotesParams): DmsObjectNote[] { | ||
const mappedNotes: DmsObjectNote[] = response.data.notes.map((note: DmsObjectNote) => { | ||
return { | ||
creator: { | ||
id: note.creator.id, | ||
displayName: note.creator.displayName | ||
}, | ||
text: note.text, | ||
created: new Date(note.created) | ||
}; | ||
}); | ||
|
||
return 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"; | ||
* | ||
* const notes: DmsObjectNote[] = getDmsObjectNotes({ | ||
* systemBaseUri: "https://steamwheedle-cartel.d-velop.cloud", | ||
* authSessionId: "dQw4w9WgXcQ" | ||
* }, { | ||
* repositoryId: "qnydFmqHuVo", | ||
* dmsObjectId: "GDYQ3PJKrT8" | ||
* }); | ||
* | ||
* notes.forEach(n => { | ||
* console.log(`${n.creator.displayName}: "${n.text}"`); | ||
* }); | ||
* | ||
* // Jastor Gallywix: "I need this taken care of ASAP!" | ||
* // Bing Zapcrackle: "I'm on it my prince." | ||
* ``` | ||
* | ||
* @category DmsObject | ||
*/ | ||
/* istanbul ignore next */ | ||
export async function getDmsObjectNotes(context: DvelopContext, params: GetDmsObjectNotesParams): Promise<DmsObjectNote[]> { | ||
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
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