Skip to content

Commit

Permalink
Add test for returning etag from bufferToUssFile
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Mar 12, 2024
1 parent 80b69a7 commit 29c548d
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,10 @@ describe("z/OS Files - Upload", () => {

describe("bufferToUssFile", () => {
const zosmfExpectSpy = jest.spyOn(ZosmfRestClient, "putExpectFullResponse");
const fakeResponseWithEtag = {
data: Buffer.from(dsName),
response: { headers: { etag: etagValue } }
};
let USSresponse: IZosFilesResponse;
beforeEach(() => {
USSresponse = undefined;
Expand Down Expand Up @@ -1679,6 +1683,27 @@ describe("z/OS Files - Upload", () => {
expect(zosmfExpectSpy).toHaveBeenCalledTimes(1);
expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, { reqHeaders: headers, resource: endpoint, writeData: data });
});
it("should return with proper response when upload USS file and request Etag back", async () => {
const data: Buffer = Buffer.from("testing");
const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_USS_FILES, dsName);
const headers = [ZosmfHeaders.X_IBM_TEXT, ZosmfHeaders.TEXT_PLAIN, ZosmfHeaders.ACCEPT_ENCODING, ZosmfHeaders.X_IBM_RETURN_ETAG];
zosmfExpectSpy.mockImplementationOnce(async () => fakeResponseWithEtag);
try {
USSresponse = await Upload.bufferToUssFile(dummySession, dsName, data, {returnEtag: true});
} catch (err) {
error = err;
}

expect(error).toBeUndefined();
expect(USSresponse).toBeDefined();
expect(USSresponse.success).toBeTruthy();
expect(USSresponse.apiResponse.etag).toBeDefined();
expect(USSresponse.apiResponse.etag).toEqual(etagValue);

expect(zosmfExpectSpy).toHaveBeenCalledTimes(1);
expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, { reqHeaders: headers, resource: endpoint, writeData: data,
dataToReturn: [CLIENT_PROPERTY.response] });
});
it("should set local encoding if specified", async () => {
const data: Buffer = Buffer.from("testing");
const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_USS_FILES, dsName);
Expand Down

0 comments on commit 29c548d

Please sign in to comment.