Skip to content

Commit

Permalink
Merge pull request #171 from andinaether/feature/createNotesForDmsObject
Browse files Browse the repository at this point in the history
Add createDmsObjectNotes() function in DMS SDK
  • Loading branch information
LenKlose authored Sep 25, 2023
2 parents ebf5c57 + 9b88d78 commit 6035ccc
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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);
});
});
});
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);
}
1 change: 1 addition & 0 deletions packages/dms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export { getRepositories } from "./repositories/get-repositories/get-repositorie
export { GetDmsObjectParams, DmsObject, getDmsObject } from "./dms-objects/get-dms-object/get-dms-object";
export { getDmsObjectMainFile, getDmsObjectPdfFile } from "./dms-objects/get-dms-object-file/get-dms-object-file";
export { CreateDmsObjectParams, createDmsObject } from "./dms-objects/create-dms-object/create-dms-object";
export { CreateDmsObjectNotesParams, createDmsObjectNotes } from "./dms-objects/create-dms-object-notes/create-dms-object-notes";
export { StoreFileTemporarilyParams, storeFileTemporarily } from "./dms-objects/store-file-temporarily/store-file-temporarily";
export { UpdateDmsObjectParams, updateDmsObject } from "./dms-objects/update-dms-object/update-dms-object";
export { UpdateDmsObjectStatusParams, updateDmsObjectStatus } from "./dms-objects/update-dms-object-status/update-dms-object-status";
Expand Down

0 comments on commit 6035ccc

Please sign in to comment.