-
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.
Endpoint for updating custom projects (#208)
- Loading branch information
1 parent
64b8326
commit df15b8b
Showing
4 changed files
with
136 additions
and
2 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
89 changes: 89 additions & 0 deletions
89
api/test/integration/custom-projects/custom-projects-update.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,89 @@ | ||
import { TestManager } from '../../utils/test-manager'; | ||
import { customProjectContract } from '@shared/contracts/custom-projects.contract'; | ||
import { User } from '@shared/entities/users/user.entity'; | ||
|
||
describe('Update 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('Update Custom Projects', () => { | ||
test('An authenticated user should be able to update/edit one of their custom projects by id', async () => { | ||
// Given | ||
const customProject = await testManager.mocks().createCustomProject({ | ||
user: { id: user.id } as User, | ||
projectName: 'A', | ||
}); | ||
|
||
// When | ||
const response = await testManager | ||
.request() | ||
.patch( | ||
`${customProjectContract.updateCustomProject.path.replace(':id', customProject.id)}`, | ||
) | ||
.set('Authorization', `Bearer ${jwtToken}`) | ||
.send({ | ||
projectName: 'B', | ||
}); | ||
|
||
// Then | ||
expect(response.status).toBe(200); | ||
expect(response.body.projectName).toBe('B'); | ||
}); | ||
|
||
test('An authenticated user should not be able to update projects that do not belong to them', async () => { | ||
// Given a custom project exists | ||
const customProject = await testManager.mocks().createCustomProject(); | ||
|
||
// When updating the custom project | ||
const response = await testManager | ||
.request() | ||
.patch( | ||
`${customProjectContract.updateCustomProject.path.replace(':id', customProject.id)}`, | ||
) | ||
.set('Authorization', `Bearer ${jwtToken}`) | ||
.send({ | ||
projectName: 'B', | ||
}); | ||
|
||
// Then | ||
expect(response.status).toBe(401); | ||
}); | ||
|
||
test('An unauthenticated user should not be able to update a custom project', async () => { | ||
// Given a custom project exists | ||
const customProject = await testManager.mocks().createCustomProject(); | ||
|
||
// When updating the custom project | ||
const response = await testManager | ||
.request() | ||
.patch( | ||
`${customProjectContract.updateCustomProject.path.replace(':id', customProject.id)}`, | ||
) | ||
.send({ | ||
projectName: 'B', | ||
}); | ||
|
||
// Then | ||
expect(response.status).toBe(401); | ||
}); | ||
}); | ||
}); |
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