generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Brad
committed
Sep 26, 2023
1 parent
ec6b353
commit 4889965
Showing
1 changed file
with
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ describe('READ', () => { | |
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
|
@@ -95,7 +96,25 @@ describe('READ', () => { | |
}); | ||
|
||
describe('UPDATE', () => { | ||
test('Update a project with PATCH to /api/projects/:id', async (done) => { | ||
beforeAll(async () => { | ||
const submittedData = { | ||
name: { | ||
firstName: 'test', | ||
lastName: 'user', | ||
}, | ||
email: '[email protected]', | ||
}; | ||
const user = await User.create(submittedData); | ||
const auth_origin = 'TEST'; | ||
token = jwt.sign( | ||
{ id: user.id, role: user.accessLevel, auth_origin }, | ||
CONFIG_AUTH.SECRET, | ||
{ | ||
expiresIn: `${CONFIG_AUTH.TOKEN_EXPIRATION_SEC}s`, | ||
}, | ||
); | ||
}) | ||
test('Update a project with PATCH to /api/projects/:id without a token', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
|
@@ -105,6 +124,7 @@ describe('UPDATE', () => { | |
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
|
@@ -117,12 +137,45 @@ describe('UPDATE', () => { | |
.put(`/api/projects/${res.body._id}`) | ||
.set(headers) | ||
.send(updatedDataPayload); | ||
expect(res2.status).toBe(200); | ||
expect(res2.status).toBe(401); | ||
|
||
// Get project | ||
const res3 = await request.get(`/api/projects/${res.body._id}`) | ||
.set(headers); | ||
expect(res3.status).toBe(200); | ||
done(); | ||
}); | ||
test('Update a project with PATCH to /api/projects/:id with a token', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
}; | ||
|
||
// Submit a project | ||
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
const updatedDataPayload = { | ||
name: 'updatedProjectName', | ||
}; | ||
|
||
// Update project | ||
const res2 = await request | ||
.put(`/api/projects/${res.body._id}`) | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(updatedDataPayload); | ||
expect(res2.status).toBe(200) | ||
|
||
// Get project | ||
const res3 = await request.get(`/api/projects/${res.body._id}`) | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
expect(res3.status).toBe(200); | ||
|
||
const APIData = res3.body; | ||
expect(APIData.name).toBe(updatedDataPayload.name); | ||
|