feat: Add availableTeams to auth.info endpoint (#3981)
* Index emails migration * feat: Add available teams to auth.info endpoint * test * separate presenter * Include data from sessions cookie, include likely logged in state * test * test: Add test for team only in session cookie * Suggested query change in PR feedback
This commit is contained in:
@@ -3,6 +3,16 @@ import env from "@server/env";
|
||||
import { buildUser, buildTeam } from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
|
||||
const mockTeamInSessionId = "1e023d05-951c-41c6-9012-c9fa0402e1c3";
|
||||
|
||||
jest.mock("@server/utils/authentication", () => {
|
||||
return {
|
||||
getSessionsInCookie() {
|
||||
return { [mockTeamInSessionId]: {} };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
@@ -13,16 +23,32 @@ beforeEach(db.flush);
|
||||
describe("#auth.info", () => {
|
||||
it("should return current authentication", async () => {
|
||||
const team = await buildTeam();
|
||||
const team2 = await buildTeam();
|
||||
const team3 = await buildTeam({
|
||||
id: mockTeamInSessionId,
|
||||
});
|
||||
|
||||
const user = await buildUser({
|
||||
teamId: team.id,
|
||||
});
|
||||
await buildUser();
|
||||
await buildUser({
|
||||
teamId: team2.id,
|
||||
email: user.email,
|
||||
});
|
||||
const res = await server.post("/api/auth.info", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
const availableTeamIds = body.data.availableTeams.map((t: any) => t.id);
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(availableTeamIds.length).toEqual(3);
|
||||
expect(availableTeamIds).toContain(team.id);
|
||||
expect(availableTeamIds).toContain(team2.id);
|
||||
expect(availableTeamIds).toContain(team3.id);
|
||||
expect(body.data.user.name).toBe(user.name);
|
||||
expect(body.data.team.name).toBe(team.name);
|
||||
expect(body.data.team.allowedDomains).toEqual([]);
|
||||
|
||||
Reference in New Issue
Block a user