mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
refactor: sessions for user without error (#8742)
This commit is contained in:
parent
fecf57c467
commit
bcbbd5c3e6
@ -43,9 +43,7 @@ export default class SessionStore implements ISessionStore {
|
||||
if (rows && rows.length > 0) {
|
||||
return rows.map(this.rowToSession);
|
||||
}
|
||||
throw new NotFoundError(
|
||||
`Could not find sessions for user with id ${userId}`,
|
||||
);
|
||||
return [];
|
||||
}
|
||||
|
||||
async get(sid: string): Promise<ISession> {
|
||||
|
@ -37,11 +37,8 @@ export default class SessionService {
|
||||
userId: number,
|
||||
maxSessions: number,
|
||||
): Promise<void> {
|
||||
let userSessions: ISession[] = [];
|
||||
try {
|
||||
// this method may throw errors when no session
|
||||
userSessions = await this.sessionStore.getSessionsForUser(userId);
|
||||
} catch (e) {}
|
||||
const userSessions: ISession[] =
|
||||
await this.sessionStore.getSessionsForUser(userId);
|
||||
const newestFirst = userSessions.sort((a, b) =>
|
||||
compareDesc(a.createdAt, b.createdAt),
|
||||
);
|
||||
|
@ -95,9 +95,8 @@ test('Can delete sessions by user', async () => {
|
||||
const sessions = await sessionService.getActiveSessions();
|
||||
expect(sessions.length).toBe(2);
|
||||
await sessionService.deleteSessionsForUser(2);
|
||||
await expect(async () => {
|
||||
await sessionService.getSessionsForUser(2);
|
||||
}).rejects.toThrow(NotFoundError);
|
||||
const noSessions = await sessionService.getSessionsForUser(2);
|
||||
expect(noSessions.length).toBe(0);
|
||||
});
|
||||
|
||||
test('Can delete session by sid', async () => {
|
||||
|
@ -357,9 +357,8 @@ test("deleting a user should delete the user's sessions", async () => {
|
||||
const userSessions = await sessionService.getSessionsForUser(user.id);
|
||||
expect(userSessions.length).toBe(1);
|
||||
await userService.deleteUser(user.id, TEST_AUDIT_USER);
|
||||
await expect(async () =>
|
||||
sessionService.getSessionsForUser(user.id),
|
||||
).rejects.toThrow(NotFoundError);
|
||||
const noSessions = await sessionService.getSessionsForUser(user.id);
|
||||
expect(noSessions.length).toBe(0);
|
||||
});
|
||||
|
||||
test('updating a user without an email should not strip the email', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user