Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkevinosullivan committed Jul 8, 2022
1 parent 4b3247c commit 22cc0cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/auth/session/storage/__tests__/battery-of-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function batteryOfTests(storageFactory: () => Promise<SessionStorage>) {

it('can find all the sessions for a given shop', async () => {
const storage = await storageFactory();
const sessionIdPrefix = 'test_session';
const sessionIdPrefix = 'find_sessions';
const sessions = [
new Session(`${sessionIdPrefix}_1`, 'shop1', 'state', true),
new Session(`${sessionIdPrefix}_2`, 'shop2', 'state', true),
Expand All @@ -119,19 +119,19 @@ export function batteryOfTests(storageFactory: () => Promise<SessionStorage>) {
expect(shop1Sessions).toBeDefined();
if (shop1Sessions) {
expect(shop1Sessions.length).toBe(2);
expect(
sessionEqual(shop1Sessions[0] as SessionInterface, sessions[0]),
).toBe(true);
expect(
sessionEqual(shop1Sessions[1] as SessionInterface, sessions[2]),
).toBe(true);
for (const session of shop1Sessions) {
expect(
sessionEqual(session as SessionInterface, sessions[0]) ||
sessionEqual(session as SessionInterface, sessions[2]),
).toBe(true);
}
}
}
});

it('can delete the sessions for a given array of ids', async () => {
const storage = await storageFactory();
const sessionIdPrefix = 'test_session';
const sessionIdPrefix = 'delete_sessions';
const sessions = [
new Session(`${sessionIdPrefix}_1`, 'shop1', 'state', true),
new Session(`${sessionIdPrefix}_2`, 'shop2', 'state', true),
Expand Down
4 changes: 2 additions & 2 deletions src/auth/session/storage/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class PostgreSQLSessionStorage implements SessionStorage {
await this.ready;
const query = `
DELETE FROM ${this.options.sessionTableName}
WHERE id IN (${ids.map(() => '?').join(',')});
WHERE id IN (${ids.map((_, i) => `$${i + 1}`).join(', ')});
`;
await this.query(query, ids);
return true;
Expand All @@ -104,7 +104,7 @@ export class PostgreSQLSessionStorage implements SessionStorage {
await this.ready;
const query = `
SELECT * FROM ${this.options.sessionTableName}
WHERE shop = ?;
WHERE shop = $1;
`;
const rows = await this.query(query, [shop]);
if (!Array.isArray(rows) || rows?.length === 0) return undefined;
Expand Down
6 changes: 4 additions & 2 deletions src/auth/session/storage/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export class RedisSessionStorage implements SessionStorage {

public async deleteSessions(ids: string[]): Promise<boolean> {
await this.ready;
await this.client.del(ids.map(this.fullKey));
for (const id of ids) {
await this.deleteSession(id);
}
return true;
}

Expand All @@ -82,7 +84,7 @@ export class RedisSessionStorage implements SessionStorage {
): Promise<SessionInterface[] | {[key: string]: unknown}[] | undefined> {
await this.ready;

const keys = await this.client.keys(`${this.options.sessionKeyPrefix}_*`);
const keys = await this.client.keys('*');
const results: SessionInterface[] = [];
for (const key of keys) {
const rawResult = await this.client.get(key);
Expand Down

0 comments on commit 22cc0cf

Please sign in to comment.