e2e/tests/7.user.test.ts (view raw)
1import { USER, USER_ID, USER_PASSWORD } from "../constants";
2import { sdk } from "../lib/gqlSdk";
3import { getJwtToken } from "../lib/strapi-utils";
4
5test("profile returns logged user profile", async () => {
6 const jwt = await getJwtToken();
7 const request = sdk.profile(undefined, {
8 authorization: `Bearer ${jwt}`,
9 });
10
11 await expect(request).resolves.toMatchObject({
12 me: {
13 id: USER_ID,
14 profile: {
15 ...USER,
16 },
17 },
18 });
19});
20
21test("profile throws error if no auth", async () => {
22 const request = sdk.profile();
23 await expect(request).rejects.toThrow("Forbidden access");
24});
25
26test("updateMe returns updated user", async () => {
27 const jwt = await getJwtToken();
28 const request = sdk.updateMe(
29 {
30 userUpdate: {
31 firstName: "Updated firstname",
32 },
33 },
34 {
35 authorization: `Bearer ${jwt}`,
36 }
37 );
38
39 await expect(request).resolves.toMatchObject({
40 updateMe: {
41 data: {
42 id: expect.any(String),
43 attributes: {
44 firstName: "Updated firstname",
45 },
46 },
47 },
48 });
49});
50
51test("updateMe updates password", async () => {
52 const jwt = await getJwtToken();
53 const request = sdk.updateMe(
54 {
55 userUpdate: {
56 password: USER_PASSWORD,
57 oldPassword: USER_PASSWORD,
58 },
59 },
60 {
61 authorization: `Bearer ${jwt}`,
62 }
63 );
64
65 await expect(request).resolves.toMatchObject({
66 updateMe: {
67 data: {
68 id: expect.any(String),
69 attributes: {
70 firstName: "Updated firstname",
71 },
72 },
73 },
74 });
75});
76
77test("updateMe throws error if no auth", async () => {
78 const request = sdk.updateMe({
79 userUpdate: {
80 firstName: "Updated firstname",
81 },
82 });
83 await expect(request).rejects.toThrow("Forbidden");
84});
85
86test("updateMe link user to an event", async () => {
87 const jwt = await getJwtToken();
88 const request = sdk.updateMe(
89 {
90 userUpdate: {
91 events: ["2"],
92 },
93 },
94 {
95 authorization: `Bearer ${jwt}`,
96 }
97 );
98
99 await expect(request).resolves.toMatchObject({
100 updateMe: {
101 data: {
102 id: expect.any(String),
103 attributes: {
104 events: {
105 data: [{ id: "1" }, { id: "2" }],
106 },
107 },
108 },
109 },
110 });
111});