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:
@@ -26,12 +26,26 @@ describe("user model", () => {
|
||||
expect(await UserAuthentication.count()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getJwtToken", () => {
|
||||
it("should set JWT secret", async () => {
|
||||
const user = await buildUser();
|
||||
expect(user.getJwtToken()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("availableTeams", () => {
|
||||
it("should return teams where another user with the same email exists", async () => {
|
||||
const user = await buildUser();
|
||||
const anotherUser = await buildUser({ email: user.email });
|
||||
|
||||
const response = await user.availableTeams();
|
||||
expect(response.length).toEqual(2);
|
||||
expect(response[0].id).toEqual(user.teamId);
|
||||
expect(response[1].id).toEqual(anotherUser.teamId);
|
||||
});
|
||||
});
|
||||
|
||||
describe("collectionIds", () => {
|
||||
it("should return read_write collections", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -405,6 +405,23 @@ class User extends ParanoidModel {
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a list of teams that have a user matching this user's email.
|
||||
*
|
||||
* @returns A promise resolving to a list of teams
|
||||
*/
|
||||
availableTeams = async () => {
|
||||
return Team.findAll({
|
||||
include: [
|
||||
{
|
||||
model: this.constructor as typeof User,
|
||||
required: true,
|
||||
where: { email: this.email },
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
demote = async (to: UserRole, options?: SaveOptions<User>) => {
|
||||
const res = await (this.constructor as typeof User).findAndCountAll({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user