Skip to content

Commit

Permalink
fix: cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlkoch committed Jun 20, 2022
1 parent ce8ade9 commit 641f687
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/parser/ShogunApplicationUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('ShogunApplicationUtil', () => {
}
});

it('is is defined', () => {
it('is defined', () => {
expect(ShogunApplicationUtil).toBeDefined();
});

Expand Down
2 changes: 1 addition & 1 deletion src/service/AppInfoService/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('AppInfoService', () => {
}
});

it('is is defined', () => {
it('is defined', () => {
expect(AppInfoService).toBeDefined();
});

Expand Down
6 changes: 5 additions & 1 deletion src/service/ApplicationService/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ describe('ApplicationService', () => {
service = new ApplicationService<Application>();
});

it('is is defined', () => {
it('is defined', () => {
expect(ApplicationService).toBeDefined();
});

it('extends the GenericService', () => {
expect(service instanceof GenericService).toBeTruthy();
});

it('has set the correct default path', () => {
expect(service.basePath).toEqual('/applications');
});

});
6 changes: 3 additions & 3 deletions src/service/AuthService/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('AuthService', () => {
}
});

it('is is defined', () => {
it('is defined', () => {
expect(AuthService).toBeDefined();
});

it('logout POST', async () => {
it('sends all required parameters to logout (logout)', async () => {
fetchMock = fetchSpy(successResponse([]));

await service.logout();
Expand All @@ -36,7 +36,7 @@ describe('AuthService', () => {
});
});

it('throws an error if the application info couldn\'t be fetched (getAppInfo)', async () => {
it('throws an error if the application info couldn\'t be fetched (logout)', async () => {
fetchMock = fetchSpy(failureResponse());

await expect(service.logout()).rejects.toThrow();
Expand Down
12 changes: 2 additions & 10 deletions src/service/CacheService/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('AppInfoService', () => {
}
});

it('is is defined', () => {
it('is defined', () => {
expect(CacheService).toBeDefined();
});

it('has set the correct defaults (evictCache)', async () => {
it('sends all required parameters to evict the cache (evictCache)', async () => {
fetchMock = fetchSpy(successResponse([]));

await service.evictCache();
Expand All @@ -35,14 +35,6 @@ describe('AppInfoService', () => {
});
});

it('calls the evict cache endpoint (evictCache)', async () => {
fetchMock = fetchSpy(successResponse());

await service.evictCache();

expect(true).toEqual(true);
});

it('throws an error if the application info couldn\'t be fetched (evictCache)', async () => {
fetchMock = fetchSpy(failureResponse());

Expand Down
6 changes: 5 additions & 1 deletion src/service/FileService/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ describe('FileService', () => {
service = new FileService<File>();
});

it('is is defined', () => {
it('is defined', () => {
expect(FileService).toBeDefined();
});

it('extends the GenericFileService', () => {
expect(service instanceof GenericFileService).toBeTruthy();
});

it('has set the correct default path', () => {
expect(service.basePath).toEqual('/files');
});

});
44 changes: 32 additions & 12 deletions src/service/GenericFileService/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('GenericFileService', () => {
}
});

it('is is defined', () => {
it('is defined', () => {
expect(GenericFileService).toBeDefined();
});

it('findAll GET', async () => {
it('sends all required parameters to return all entities (findAll)', async () => {
fetchMock = fetchSpy(successResponse([]));

await service.findAll();
Expand Down Expand Up @@ -80,10 +80,10 @@ describe('GenericFileService', () => {
await expect(service.findAll()).rejects.toThrow();
});

it('findOne GET', async () => {
it('sends all required parameters to return a single entity (findOne)', async () => {
fetchMock = fetchSpy(successResponse([]));

const resp = await service.findOne('db5f69fa-e8f6-42a6-a305-d2555d7d4d08');
await service.findOne('db5f69fa-e8f6-42a6-a305-d2555d7d4d08');

expect(fetchMock).toHaveBeenCalledWith('/dummy/db5f69fa-e8f6-42a6-a305-d2555d7d4d08', {
headers: {},
Expand All @@ -107,19 +107,39 @@ describe('GenericFileService', () => {
await expect(service.findOne('db5f69fa-e8f6-42a6-a305-d2555d7d4d08')).rejects.toThrow();
});

it('add POST', async () => {
it('sends all required parameter to create an entity (upload)', async () => {
fetchMock = fetchSpy(successResponse([]));
const file = new File([''], 'filename', {type: 'text/html'});

const resp = await service.upload(new File([''], 'filename', {type: 'text/html'}));
await service.upload(file);

const body = new FormData();
body.append('file', file);

expect(fetchMock).toHaveBeenCalledWith('/dummy/upload', {
body: new FormData(),
body: body,
headers: {},
method: 'POST'
});
});

it('returns the created entity (add)', async () => {
it('sends all required parameter to create an entity on disk (upload)', async () => {
fetchMock = fetchSpy(successResponse([]));
const file = new File([''], 'filename', {type: 'text/html'});

await service.upload(file, true);

const body = new FormData();
body.append('file', file);

expect(fetchMock).toHaveBeenCalledWith('/dummy/uploadToFileSystem', {
body: body,
headers: {},
method: 'POST'
});
});

it('returns the created entity (upload)', async () => {
const response = {
id: 1
};
Expand All @@ -131,24 +151,24 @@ describe('GenericFileService', () => {
expect(resp).toEqual(response);
});

it('throws an error if an entity couldn\'t be created (add)', async () => {
it('throws an error if an entity couldn\'t be created (upload)', async () => {
fetchMock = fetchSpy(failureResponse());

await expect(service.upload(new File([''], 'filename', {type: 'text/html'}))).rejects.toThrow();
});

it('delete DELETE', async () => {
it('sends all required parameters to delete an entity (delete)', async () => {
fetchMock = fetchSpy(successResponse([]));

const resp = await service.delete('db5f69fa-e8f6-42a6-a305-d2555d7d4d08');
await service.delete('db5f69fa-e8f6-42a6-a305-d2555d7d4d08');

expect(fetchMock).toHaveBeenCalledWith('/dummy/db5f69fa-e8f6-42a6-a305-d2555d7d4d08', {
headers: {},
method: 'DELETE'
});
});

it('delete', async () => {
it('returns the deleted entity (delete)', async () => {
const response = {
id: 1
};
Expand Down
28 changes: 14 additions & 14 deletions src/service/GenericService/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('GenericService', () => {
}
});

it('is is defined', () => {
it('is defined', () => {
expect(GenericService).toBeDefined();
});

it('findAll GET', async () => {
it('sends all required parameters to return all entities (findAll)', async () => {
fetchMock = fetchSpy(successResponse([]));

await service.findAll();
Expand Down Expand Up @@ -80,10 +80,10 @@ describe('GenericService', () => {
await expect(service.findAll()).rejects.toThrow();
});

it('findOne GET', async () => {
it('sends all required parameters to return a single entity (findOne)', async () => {
fetchMock = fetchSpy(successResponse([]));

const resp = await service.findOne(1);
await service.findOne(1);

expect(fetchMock).toHaveBeenCalledWith('/dummy/1', {
headers: {},
Expand All @@ -109,10 +109,10 @@ describe('GenericService', () => {
await expect(service.findOne(1)).rejects.toThrow();
});

it('add POST', async () => {
it('sends all required parameter to create an entity (add)', async () => {
fetchMock = fetchSpy(successResponse([]));

const resp = await service.add({dummyField: 'dummyValue'});
await service.add({dummyField: 'dummyValue'});

expect(fetchMock).toHaveBeenCalledWith('/dummy', {
body: '{\"dummyField\":\"dummyValue\"}',
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('GenericService', () => {
await expect(service.add({dummyField: 'dummyValue'})).rejects.toThrow();
});

it('delete DELETE', async () => {
it('sends all required parameters to delete an entity (delete)', async () => {
fetchMock = fetchSpy(successResponse([]));

const resp = await service.delete(1);
Expand All @@ -152,7 +152,7 @@ describe('GenericService', () => {
});
});

it('delete', async () => {
it('returns the deleted entity (delete)', async () => {
const response = {
id: 1
};
Expand All @@ -170,10 +170,10 @@ describe('GenericService', () => {
await expect(service.delete(1)).rejects.toThrow();
});

it('update PUT', async () => {
it('sends all required parameters to update an entity (update)', async () => {
fetchMock = fetchSpy(successResponse([]));

const resp = await service.update({id: 1, dummyField: 'dummyValue'});
await service.update({id: 1, dummyField: 'dummyValue'});

expect(fetchMock).toHaveBeenCalledWith('/dummy/1', {
body: '{\"id\":1,\"dummyField\":\"dummyValue\"}',
Expand All @@ -184,7 +184,7 @@ describe('GenericService', () => {
});
});

it('update', async () => {
it('returns the updated entity (update)', async () => {
const response = {
id: 1
};
Expand All @@ -202,10 +202,10 @@ describe('GenericService', () => {
await expect(service.update({dummyField: 'dummyValue'})).rejects.toThrow();
});

it('updatePartial PATCH', async () => {
it('sends all required parameters to partially update an entity (updatePartial)', async () => {
fetchMock = fetchSpy(successResponse([]));

const resp = await service.updatePartial({id: 1, dummyField: 'dummyValue'});
await service.updatePartial({id: 1, dummyField: 'dummyValue'});

expect(fetchMock).toHaveBeenCalledWith('/dummy/1', {
body: '{\"id\":1,\"dummyField\":\"dummyValue\"}',
Expand All @@ -216,7 +216,7 @@ describe('GenericService', () => {
});
});

it('updatePartial', async () => {
it('returns the updated entity (updatePartial)', async () => {
const response = {
id: 1
};
Expand Down
6 changes: 5 additions & 1 deletion src/service/GroupService/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ describe('GroupService', () => {
service = new GroupService<Group<KeycloakGroupRepresentation>, KeycloakGroupRepresentation>();
});

it('is is defined', () => {
it('is defined', () => {
expect(GroupService).toBeDefined();
});

it('extends the GenericService', () => {
expect(service instanceof GenericService).toBeTruthy();
});

it('has set the correct default path', () => {
expect(service.basePath).toEqual('/groups');
});

});
43 changes: 42 additions & 1 deletion src/service/ImageFileService/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,61 @@
import ImageFileService from '.';
import ImageFile from '../../model/ImageFile';
import GenericFileService from '../GenericFileService';
import fetchSpy, { failureResponse, successResponse } from '../../spec/fetchSpy';

describe('ImageFileService', () => {
let fetchMock: jest.SpyInstance;
let service: ImageFileService<ImageFile>;

beforeEach(() => {
service = new ImageFileService<ImageFile>();
});

it('is is defined', () => {
afterEach(() => {
if (fetchMock) {
fetchMock.mockReset();
fetchMock.mockRestore();
}
});

it('is defined', () => {
expect(ImageFileService).toBeDefined();
});

it('extends the GenericFileService', () => {
expect(service instanceof GenericFileService).toBeTruthy();
});

it('has set the correct default path', () => {
expect(service.basePath).toEqual('/imagefiles');
});


it('sends all required parameters to return a single entity (findOneThumbnail)', async () => {
fetchMock = fetchSpy(successResponse([]));

await service.findOneThumbnail('db5f69fa-e8f6-42a6-a305-d2555d7d4d08');

expect(fetchMock).toHaveBeenCalledWith('/imagefiles/db5f69fa-e8f6-42a6-a305-d2555d7d4d08/thumbnail', {
headers: {},
method: 'GET'
});
});

it('returns a single entity (findOneThumbnail)', async () => {
const response = new Blob();

fetchMock = fetchSpy(successResponse(response));

const resp = await service.findOneThumbnail('db5f69fa-e8f6-42a6-a305-d2555d7d4d08');

expect(resp).toEqual(response);
});

it('throws an error if a single entity couldn\'t be fetched (findOneThumbnail)', async () => {
fetchMock = fetchSpy(failureResponse());

await expect(service.findOneThumbnail('db5f69fa-e8f6-42a6-a305-d2555d7d4d08')).rejects.toThrow();
});

});
Loading

0 comments on commit 641f687

Please sign in to comment.