-
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.
- Loading branch information
1 parent
3738456
commit 340f071
Showing
3 changed files
with
126 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
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
87 changes: 87 additions & 0 deletions
87
api/test/integration/custom-projects/custom-projects-delete.spec.ts
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,87 @@ | ||
import { TestManager } from '../../utils/test-manager'; | ||
import { customProjectContract } from '@shared/contracts/custom-projects.contract'; | ||
import { User } from '@shared/entities/users/user.entity'; | ||
import { HttpStatus } from '@nestjs/common'; | ||
|
||
describe('Delete Custom projects', () => { | ||
let testManager: TestManager; | ||
let jwtToken: string; | ||
let user: User; | ||
|
||
beforeAll(async () => { | ||
testManager = await TestManager.createTestManager(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
({ jwtToken, user } = await testManager.setUpTestUser()); | ||
await testManager.ingestCountries(); | ||
await testManager.ingestExcel(jwtToken); | ||
}); | ||
|
||
afterEach(async () => { | ||
await testManager.clearDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testManager.close(); | ||
}); | ||
|
||
describe('Delete Custom Projects', () => { | ||
test('An anonymous user should be UNAUTHORIZED to delete a custom project', async () => { | ||
// Given | ||
const customProject = await testManager.mocks().createCustomProject({ | ||
user: { id: user.id } as User, | ||
}); | ||
|
||
// When deleting the custom project | ||
const response = await testManager | ||
.request() | ||
.delete(customProjectContract.deleteCustomProjects.path) | ||
.send({ ids: [customProject.id] }); | ||
|
||
// Then | ||
expect(response.status).toBe(HttpStatus.UNAUTHORIZED); | ||
expect(response.body.errors).toBeDefined(); | ||
}); | ||
|
||
test.only('An authenticated user should not be able to delete projects that do not belong to them', async () => { | ||
// Given a custom project exists | ||
const customProject = await testManager.mocks().createCustomProject(); | ||
|
||
// When deleting the custom project | ||
const response = await testManager | ||
.request() | ||
.delete(customProjectContract.deleteCustomProjects.path) | ||
.set('Authorization', `Bearer ${jwtToken}`) | ||
.send({ ids: [customProject.id] }); | ||
|
||
// Then | ||
expect(response.status).toBe(HttpStatus.UNAUTHORIZED); | ||
}); | ||
|
||
test('An authenticated user should be able to delete projects', async () => { | ||
// Given a custom project exists | ||
const customProject = await testManager.mocks().createCustomProject({ | ||
user: { id: user.id } as User, | ||
}); | ||
|
||
// When deleting the custom project | ||
const response = await testManager | ||
.request() | ||
.delete(customProjectContract.deleteCustomProjects.path) | ||
.set('Authorization', `Bearer ${jwtToken}`) | ||
.send({ ids: [customProject.id] }); | ||
|
||
expect(response.status).toBe(HttpStatus.OK); | ||
|
||
// Then the project should no longer exist | ||
const getProjectResponse = await testManager | ||
.request() | ||
.get( | ||
`${customProjectContract.getCustomProject.path}/${customProject.id}`, | ||
) | ||
.set('Authorization', `Bearer ${jwtToken}`); | ||
expect(getProjectResponse.status).toBe(HttpStatus.NOT_FOUND); | ||
}); | ||
}); | ||
}); |