From 7b7a80c502406a7df9c9eff4b0a787180cfe130b Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Tue, 27 Jul 2021 08:20:30 +0100 Subject: [PATCH] chore(root-folder-not-found): add test --- src/SASViyaApiClient.spec.ts | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/SASViyaApiClient.spec.ts diff --git a/src/SASViyaApiClient.spec.ts b/src/SASViyaApiClient.spec.ts new file mode 100644 index 0000000..4063817 --- /dev/null +++ b/src/SASViyaApiClient.spec.ts @@ -0,0 +1,51 @@ +import { Logger, LogLevel } from '@sasjs/utils/logger' +import { RequestClient } from './request/RequestClient' +import { SASViyaApiClient } from './SASViyaApiClient' +import { Folder } from './types' +import { RootFolderNotFoundError } from './types/errors' + +const mockFolder: Folder = { + id: '1', + uri: '/folder', + links: [], + memberCount: 1 +} + +const requestClient = new (>RequestClient)() +const sasViyaApiClient = new SASViyaApiClient( + 'https://test.com', + '/test', + 'test context', + requestClient +) + +describe('SASViyaApiClient', () => { + beforeEach(() => { + ;(process as any).logger = new Logger(LogLevel.Off) + setupMocks() + }) + + it('should throw an error when the root folder is not found on the server', async () => { + jest + .spyOn(requestClient, 'get') + .mockImplementation(() => Promise.reject('Not Found')) + const error = await sasViyaApiClient + .createFolder('test', '/foo') + .catch((e) => e) + expect(error).toBeInstanceOf(RootFolderNotFoundError) + }) +}) + +const setupMocks = () => { + jest + .spyOn(requestClient, 'get') + .mockImplementation(() => + Promise.resolve({ result: mockFolder, etag: '', status: 200 }) + ) + + jest + .spyOn(requestClient, 'post') + .mockImplementation(() => + Promise.resolve({ result: mockFolder, etag: '', status: 200 }) + ) +}