Skip to content

Commit 047aced

Browse files
committed
Fixed authorization tests
1 parent 5e585ea commit 047aced

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

apps/webapp/test/authorization.test.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ describe("checkAuthorization", () => {
6464
});
6565
expect(result.authorized).toBe(false);
6666
if (!result.authorized) {
67-
expect(result.reason).toBe("Missing required permission for read on runs");
67+
expect(result.reason).toBe(
68+
"Public Access Token is missing required permissions. Permissions required for 'read:runs:run_5678' but token has the following permissions: 'read:runs:run_1234', 'read:tasks', 'read:tags:tag_5678'. See https://trigger.dev/docs/frontend/overview#authentication for more information."
69+
);
6870
}
6971
});
7072

@@ -107,23 +109,29 @@ describe("checkAuthorization", () => {
107109
});
108110
expect(result1.authorized).toBe(false);
109111
if (!result1.authorized) {
110-
expect(result1.reason).toBe("Entity has no permissions");
112+
expect(result1.reason).toBe(
113+
"Public Access Token has no permissions. See https://trigger.dev/docs/frontend/overview#authentication for more information."
114+
);
111115
}
112116

113117
const result2 = checkAuthorization(publicJwtEntityNoPermissions, "read", {
114118
tasks: ["task_1", "task_2"],
115119
});
116120
expect(result2.authorized).toBe(false);
117121
if (!result2.authorized) {
118-
expect(result2.reason).toBe("Entity has no permissions");
122+
expect(result2.reason).toBe(
123+
"Public Access Token has no permissions. See https://trigger.dev/docs/frontend/overview#authentication for more information."
124+
);
119125
}
120126

121127
const result3 = checkAuthorization(publicJwtEntityNoPermissions, "read", {
122128
tags: "tag_5678",
123129
});
124130
expect(result3.authorized).toBe(false);
125131
if (!result3.authorized) {
126-
expect(result3.reason).toBe("Entity has no permissions");
132+
expect(result3.reason).toBe(
133+
"Public Access Token has no permissions. See https://trigger.dev/docs/frontend/overview#authentication for more information."
134+
);
127135
}
128136
});
129137
});
@@ -142,7 +150,9 @@ describe("checkAuthorization", () => {
142150
const result = checkAuthorization(entityUndefinedPermissions, "read", { runs: "run_1234" });
143151
expect(result.authorized).toBe(false);
144152
if (!result.authorized) {
145-
expect(result.reason).toBe("Entity has no permissions");
153+
expect(result.reason).toBe(
154+
"Public Access Token has no permissions. See https://trigger.dev/docs/frontend/overview#authentication for more information."
155+
);
146156
}
147157
});
148158

@@ -151,7 +161,9 @@ describe("checkAuthorization", () => {
151161
const result = checkAuthorization(entityEmptyPermissions, "read", { runs: "run_1234" });
152162
expect(result.authorized).toBe(false);
153163
if (!result.authorized) {
154-
expect(result.reason).toBe("Entity has no permissions");
164+
expect(result.reason).toBe(
165+
"Public Access Token has no permissions. See https://trigger.dev/docs/frontend/overview#authentication for more information."
166+
);
155167
}
156168
});
157169

@@ -163,7 +175,9 @@ describe("checkAuthorization", () => {
163175
});
164176
expect(result.authorized).toBe(false);
165177
if (!result.authorized) {
166-
expect(result.reason).toBe("Missing required permission for read on tags");
178+
expect(result.reason).toBe(
179+
"Public Access Token is missing required permissions. Permissions required for 'read:tags:tag_3456' but token has the following permissions: 'read:runs:run_1234', 'read:tasks', 'read:tags:tag_5678'. See https://trigger.dev/docs/frontend/overview#authentication for more information."
180+
);
167181
}
168182
});
169183

@@ -229,7 +243,9 @@ describe("checkAuthorization", () => {
229243
);
230244
expect(result.authorized).toBe(false);
231245
if (!result.authorized) {
232-
expect(result.reason).toBe("Missing required permission for read on tasks");
246+
expect(result.reason).toBe(
247+
"Public Access Token is missing required permissions. Permissions required for 'read:tasks:task_1234' but token has the following permissions: 'read:all'. See https://trigger.dev/docs/frontend/overview#authentication for more information."
248+
);
233249
}
234250
});
235251

@@ -264,7 +280,9 @@ describe("checkAuthorization", () => {
264280
});
265281
expect(result2.authorized).toBe(false);
266282
if (!result2.authorized) {
267-
expect(result2.reason).toBe("Missing required permission for read on runs");
283+
expect(result2.reason).toBe(
284+
"Public Access Token is missing required permissions. Permissions required for 'read:runs:run_5678' but token has the following permissions: 'read:tasks', 'read:tags'. See https://trigger.dev/docs/frontend/overview#authentication for more information."
285+
);
268286
}
269287
});
270288
});
@@ -295,7 +313,9 @@ describe("checkAuthorization", () => {
295313
);
296314
expect(result.authorized).toBe(false);
297315
if (!result.authorized) {
298-
expect(result.reason).toBe("Missing required permission for read on runs");
316+
expect(result.reason).toBe(
317+
"Public Access Token is missing required permissions. Permissions required for 'read:runs:run_5678' but token has the following permissions: 'read:tasks'. See https://trigger.dev/docs/frontend/overview#authentication for more information."
318+
);
299319
}
300320
});
301321
});

0 commit comments

Comments
 (0)