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