e2e/tests/2.login.test.ts (view raw)
1import { sdk } from "../lib/gqlSdk";
2import { USER, USER_PASSWORD } from "../constants";
3
4test("login returns JWT token", async () => {
5 const request = sdk.login({
6 identifier: USER.username as string,
7 password: USER_PASSWORD,
8 });
9
10 await expect(request).resolves.toMatchObject({
11 login: {
12 jwt: expect.stringMatching(/(^[\w-]*\.[\w-]*\.[\w-]*$)/),
13 user: expect.objectContaining({
14 id: expect.stringMatching("1"),
15 }),
16 },
17 });
18});
19
20test("login returns bad request for erroneous credentials", async () => {
21 const request = sdk.login({
22 identifier: "not_exists@octree.ch",
23 password: "yolo",
24 });
25
26 await expect(request).rejects.toMatchObject({
27 response: {
28 errors: expect.arrayContaining([
29 expect.objectContaining({
30 message: "Bad Request",
31 }),
32 ]),
33 },
34 });
35});