Skip to content

Commit 0d73c89

Browse files
committed
feat(api): add multi-school role access test
1 parent e5f6c3b commit 0d73c89

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

modules/services/api/src/edu/controllers/roles/specs/context.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type Context = {
1414
tokens: {
1515
admin: string;
1616
readOnly: string;
17+
oneAndTwoAdmin: string;
1718
};
1819
};
1920
two: {
@@ -23,6 +24,7 @@ export type Context = {
2324
};
2425
tokens: {
2526
admin: string;
27+
oneAndTwoAdmin: string;
2628
};
2729
};
2830
three: {
@@ -110,6 +112,11 @@ export const createContext = async (
110112
[{ sid: schoolThree.id, p: ['roles:create', 'roles:read'] }],
111113
);
112114

115+
const oneAndTwoAdmin = await authService.generateTokens(faker.string.uuid(), [
116+
{ sid: schoolOne.id, p: oneAdminRole.permissions },
117+
{ sid: schoolTwo.id, p: twoAdminRole.permissions },
118+
]);
119+
113120
const emptyTokenNoPermissions = await authService.generateTokens(
114121
faker.string.uuid(),
115122
[],
@@ -129,6 +136,7 @@ export const createContext = async (
129136
tokens: {
130137
admin: oneTokenAdmin.accessToken,
131138
readOnly: oneTokenReadonly.accessToken,
139+
oneAndTwoAdmin: oneAndTwoAdmin.accessToken,
132140
},
133141
},
134142
two: {
@@ -138,6 +146,7 @@ export const createContext = async (
138146
},
139147
tokens: {
140148
admin: twoTokenAdmin.accessToken,
149+
oneAndTwoAdmin: oneAndTwoAdmin.accessToken,
141150
},
142151
},
143152
three: {

modules/services/api/src/edu/controllers/roles/specs/roles.controller.e2e.get.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ describe('/edu/roles', () => {
5959
});
6060
});
6161

62+
it(`GET /edu/roles returns only permitted roles (multiple schools)`, async () => {
63+
return request(app.getHttpServer())
64+
.get(Routes().edu.roles.find())
65+
.set('Authorization', `Bearer ${ctx.one.tokens.oneAndTwoAdmin}`)
66+
.expect(200)
67+
.expect({
68+
items: instanceToPlain(
69+
mapper.mapArray(
70+
[ctx.one.roles.admin, ctx.one.roles.readonly, ctx.two.roles],
71+
entities.Role,
72+
dto.RoleSummary,
73+
),
74+
),
75+
});
76+
});
77+
6278
/* -------------------------------------------------------------------------- */
6379
/* Negative Cases */
6480
/* -------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)