-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1553 from flacial/fixCreateSubmission
Mitigate the issue of creating a submission based on the cliToken ID
- Loading branch information
Showing
5 changed files
with
96 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ const mockUserInfo = { | |
password: '$2b$10$W9KwQ6Sbi0RJjD2GZYX9BugAtgSm/W999gNW1f/XiRcI6NiC9pTdK', | ||
email: '[email protected]', | ||
isAdmin: false, | ||
cliToken: 'KfizzIlWp111fizzDbuzzr' | ||
cliToken: 'W29iamVjdCBPYmplY3Rd' | ||
} | ||
|
||
const res = {} | ||
|
@@ -26,15 +26,39 @@ const next = () => {} | |
describe('User Middleware', () => { | ||
beforeEach(() => { | ||
prismaMock.user.findUnique.mockResolvedValue(mockUserInfo) | ||
prismaMock.user.findFirst.mockResolvedValue(mockUserInfo) | ||
}) | ||
test('Should return null when userId property of req.session is not there', async () => { | ||
const req = { session: '' } | ||
const req = { | ||
session: '', | ||
headers: { | ||
authorization: null | ||
} | ||
} | ||
await userMiddleware(req, res, next) | ||
expect(req.user).toBeNull | ||
}) | ||
|
||
test('Should return correct info from database if session.userId exists', async () => { | ||
const req = { session: { userId: 'noob' } } | ||
const req = { | ||
session: { | ||
userId: 'noob' | ||
}, | ||
headers: { | ||
authorization: null | ||
} | ||
} | ||
await userMiddleware(req, res, next) | ||
expect(req.user).toEqual(mockUserInfo) | ||
}) | ||
test('Should return correct info from database if authorization header exists', async () => { | ||
const req = { | ||
session: { userId: 'noob' }, | ||
headers: { | ||
authorization: | ||
'Bearer eyJpZCI6MSwiY2xpVG9rZW4iOiJXMjlpYW1WamRDQlBZbXBsWTNSZCJ9' | ||
} | ||
} | ||
await userMiddleware(req, res, next) | ||
expect(req.user).toEqual(mockUserInfo) | ||
}) | ||
|
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
be707fe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: