Skip to content

Commit

Permalink
test: setting the cookie domain
Browse files Browse the repository at this point in the history
  • Loading branch information
korac committed Jan 27, 2022
1 parent ce2682f commit ac384e2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/api/__tests__/loginHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ describe('[api] loginHandler', () => {
jest.restoreAllMocks();
});

it('should set the domain if configured', async () => {
const { req, res } = createMocks(
{ method: 'POST', body: { password: 'password' } },
{ eventEmitter: EventEmitter },
);

const domain = 'storyofams.com';
await loginHandler('password', { domain })(req, res);

expect(res._getStatusCode()).toBe(200);
expect(res._getHeaders()).toMatchObject({
'set-cookie': expect.stringMatching(
new RegExp(
`^next-password-protect=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9\\..+\\..+; Domain=${domain}; Path=\\/; HttpOnly$`,
),
),
});
});

it('should reject on incorrect password', async () => {
const { req, res } = createMocks(
{ method: 'POST', body: { password: 'incorrect' } },
Expand Down

0 comments on commit ac384e2

Please sign in to comment.