Initial import of zappier-edge from zapier monorepo
This commit is contained in:
commit
525edd7469
128 changed files with 20479 additions and 0 deletions
32
tests/db-session.test.ts
Normal file
32
tests/db-session.test.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import Database from 'better-sqlite3';
|
||||
import { SqliteSessionRepo } from '../src/db/session-repo';
|
||||
|
||||
describe('SqliteSessionRepo', () => {
|
||||
it('creates and retrieves sessions within the TTL', () => {
|
||||
const repo = new SqliteSessionRepo(new Database(':memory:'));
|
||||
const s = repo.create('cust_1', 60_000);
|
||||
expect(s.customerId).toBe('cust_1');
|
||||
expect(repo.get(s.token, s.createdMs + 30_000)?.customerId).toBe('cust_1');
|
||||
});
|
||||
|
||||
it('persists sessions across instances (same db)', () => {
|
||||
const db = new Database(':memory:');
|
||||
const first = new SqliteSessionRepo(db);
|
||||
const s = first.create('cust_1', 60_000);
|
||||
const second = new SqliteSessionRepo(db);
|
||||
expect(second.get(s.token, s.createdMs + 1_000)?.customerId).toBe('cust_1');
|
||||
});
|
||||
|
||||
it('expires sessions after the TTL', () => {
|
||||
const repo = new SqliteSessionRepo(new Database(':memory:'));
|
||||
const s = repo.create('cust_1', 60_000);
|
||||
expect(repo.get(s.token, s.createdMs + 61_000)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('deletes sessions (logout)', () => {
|
||||
const repo = new SqliteSessionRepo(new Database(':memory:'));
|
||||
const s = repo.create('cust_1', 60_000);
|
||||
repo.delete(s.token);
|
||||
expect(repo.get(s.token, s.createdMs)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue