-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TM-1273] Implement tests for the delayed job controller.
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { DelayedJobsController } from './delayed-jobs.controller'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { NotFoundException } from '@nestjs/common'; | ||
import { DelayedJobFactory } from '@terramatch-microservices/database/factories'; | ||
import { Resource } from '@terramatch-microservices/common/util'; | ||
|
||
describe('DelayedJobsController', () => { | ||
let controller: DelayedJobsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [DelayedJobsController] | ||
}).compile(); | ||
|
||
controller = module.get<DelayedJobsController>(DelayedJobsController); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}) | ||
|
||
it('should throw not found if the delayed job does not exist', async () => { | ||
await expect(controller.findOne('asdf')).rejects | ||
.toThrow(NotFoundException); | ||
}); | ||
|
||
it('should return the job definition when the delayed job does exist', async () => { | ||
const { uuid, statusCode, payload } = await DelayedJobFactory.create(); | ||
const result = await controller.findOne(uuid); | ||
const resource = result.data as Resource; | ||
expect(resource.type).toBe('delayedJobs'); | ||
expect(resource.id).toBe(uuid); | ||
expect(resource.attributes.statusCode).toBe(statusCode); | ||
// TODO This will need an update when `payload` has been converted to a jsonb field | ||
expect(resource.attributes.payload).toBe(payload); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { FactoryGirl } from 'factory-girl-ts'; | ||
import { DelayedJob } from '../entities'; | ||
|
||
export const DelayedJobFactory = FactoryGirl.define(DelayedJob, async () => ({ | ||
uuid: crypto.randomUUID(), | ||
status: 'succeeded', | ||
statusCode: 200, | ||
// TODO: this will need an update when `payload` has been converted to a jsonb field | ||
payload: '{ "data": "test" }' | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './delayed-job.factory'; | ||
export * from './organisation.factory'; | ||
export * from './user.factory'; |