Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienMattiussi committed Oct 19, 2023
1 parent 9e7875c commit 9096ff2
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions src/api/controller/api/precomputed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
putPrecomputed,
deletePrecomputed,
} from './precomputed';
import { getActiveJob, cancelJob } from '../../workers/tools';

jest.mock('../../workers/tools', () => ({
getActiveJob: jest.fn(),
Expand Down Expand Up @@ -73,8 +72,6 @@ describe('Precomputed controller', () => {

await putPrecomputed(ctx, 42);

expect(ctx.precomputed.findOneById).toHaveBeenCalledWith(42);
expect(ctx.dataset.removeAttribute).toHaveBeenCalledWith('NAME');
expect(ctx.precomputed.update).toHaveBeenCalledWith(
42,
'my updated precomputed',
Expand All @@ -87,7 +84,7 @@ describe('Precomputed controller', () => {
const ctx = {
request: { body: 'my updated precomputed' },
precomputed: {
findOneById: async () => {
update: async () => {
throw new Error('ERROR!');
},
},
Expand All @@ -101,36 +98,13 @@ describe('Precomputed controller', () => {
});

describe('deletePrecomputed', () => {
it('should delete existing dataset data based on the precomputed name and then delete it', async () => {
const ctx = {
precomputed: {
findOneById: jest.fn(() => ({ name: 'NAME' })),
delete: jest.fn(),
},
dataset: { removeAttribute: jest.fn() },
};
getActiveJob.mockResolvedValue({
data: { id: 42, jobType: 'precomputer' },
});

await deletePrecomputed(ctx, 42);

expect(ctx.precomputed.findOneById).toHaveBeenCalledWith(42);
expect(ctx.dataset.removeAttribute).toHaveBeenCalledWith('NAME');
expect(ctx.precomputed.delete).toHaveBeenCalledWith(42);
expect(cancelJob).toHaveBeenCalled();
expect(ctx.status).toBe(200);
});

it('should return a 403 on error if an error occured', async () => {
const ctx = {
precomputed: {
findOneById: async () => {
delete: async () => {
throw new Error('ERROR!');
},
delete: jest.fn(),
},
dataset: { removeAttribute: jest.fn() },
};

await deletePrecomputed(ctx, 42);
Expand Down

0 comments on commit 9096ff2

Please sign in to comment.