-
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.
feat(api): Add getCustomProject and getCustomProjects contracts and e…
…ndpoints
- Loading branch information
Showing
8 changed files
with
942 additions
and
6 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
120 changes: 120 additions & 0 deletions
120
api/test/integration/custom-projects/custom-projects-read.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,120 @@ | ||
import { TestManager } from '../../utils/test-manager'; | ||
import { customProjectContract } from '@shared/contracts/custom-projects.contract'; | ||
import { CustomProject } from '@shared/entities/custom-project.entity'; | ||
import { User } from '@shared/entities/users/user.entity'; | ||
|
||
describe('Read 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('Read Custom Projects', () => { | ||
test('An anonymous user should be UNAUTHORIZED to read a custom project by its id', async () => { | ||
// Given | ||
const customProject = await testManager.mocks().createCustomProject({ | ||
user: { id: user.id } as User, | ||
}); | ||
|
||
// When | ||
const response = await testManager | ||
.request() | ||
.get( | ||
`${customProjectContract.getCustomProject.path.replace(':id', customProject.id)}`, | ||
) | ||
.send(); | ||
|
||
// Then | ||
expect(response.status).toBe(401); | ||
expect(response.body.errors).toBeDefined(); | ||
}); | ||
|
||
test('An anonymous user should be UNAUTHORIZED to read any custom projects', async () => { | ||
// Given | ||
const customProject = await testManager.mocks().createCustomProject({ | ||
user: { id: user.id } as User, | ||
}); | ||
|
||
// When | ||
const response = await testManager | ||
.request() | ||
.get( | ||
`${customProjectContract.getCustomProject.path.replace(':id', customProject.id)}`, | ||
) | ||
.send(); | ||
|
||
// Then | ||
expect(response.status).toBe(401); | ||
expect(response.body.errors).toBeDefined(); | ||
}); | ||
|
||
test('An authenticated user should be able to read one of its custom projects by id', async () => { | ||
// Given | ||
const customProject = await testManager.mocks().createCustomProject({ | ||
user: { id: user.id } as User, | ||
}); | ||
|
||
// When | ||
const response = await testManager | ||
.request() | ||
.get( | ||
`${customProjectContract.getCustomProject.path.replace(':id', customProject.id)}`, | ||
) | ||
.set('Authorization', `Bearer ${jwtToken}`) | ||
.send(); | ||
|
||
// Then | ||
expect(response.status).toBe(200); | ||
expect(response.body.data.id).toBe(customProject.id); | ||
}); | ||
|
||
test('An authenticated user should be able to retrieve its custom projects', async () => { | ||
// Given | ||
const { createCustomProject } = testManager.mocks(); | ||
const [customProject1, customProject2] = await Promise.all([ | ||
createCustomProject({ | ||
user: { id: user.id } as User, | ||
}), | ||
createCustomProject({ | ||
id: '2d8fdf38-3295-4970-b194-af503a2a6039', | ||
user: { id: user.id } as User, | ||
}), | ||
]); | ||
|
||
// When | ||
const response = await testManager | ||
.request() | ||
.get(customProjectContract.getCustomProjects.path) | ||
.set('Authorization', `Bearer ${jwtToken}`) | ||
.send(); | ||
|
||
// Then | ||
expect(response.status).toBe(200); | ||
const responseData = response.body.data; | ||
expect(responseData.length).toBe(2); | ||
expect( | ||
responseData.find((cp: CustomProject) => cp.id === customProject1.id), | ||
).toBeDefined(); | ||
expect( | ||
responseData.find((cp: CustomProject) => cp.id === customProject2.id), | ||
).toBeDefined(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.