mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
refactor(server): trip-access primitives async at every caller
This commit is contained in:
@@ -21,17 +21,17 @@ describe('canAccessTrip', () => {
|
||||
db.exec('DELETE FROM trip_members; DELETE FROM trips; DELETE FROM users;');
|
||||
});
|
||||
|
||||
it('returns the trip currency for the owner (#1543)', () => {
|
||||
it('returns the trip currency for the owner (#1543)', async () => {
|
||||
const owner = seedUser('owner');
|
||||
const tripId = Number(
|
||||
db.prepare("INSERT INTO trips (user_id, title, currency) VALUES (?, 'Trip', 'RUB')")
|
||||
.run(owner).lastInsertRowid,
|
||||
);
|
||||
|
||||
expect(canAccessTrip(tripId, owner)).toMatchObject({ id: tripId, user_id: owner, currency: 'RUB' });
|
||||
expect(await canAccessTrip(tripId, owner)).toMatchObject({ id: tripId, user_id: owner, currency: 'RUB' });
|
||||
});
|
||||
|
||||
it('returns the trip currency for a member too', () => {
|
||||
it('returns the trip currency for a member too', async () => {
|
||||
const owner = seedUser('owner2');
|
||||
const member = seedUser('member2');
|
||||
const tripId = Number(
|
||||
@@ -40,17 +40,17 @@ describe('canAccessTrip', () => {
|
||||
);
|
||||
db.prepare('INSERT INTO trip_members (trip_id, user_id) VALUES (?, ?)').run(tripId, member);
|
||||
|
||||
expect(canAccessTrip(tripId, member)).toMatchObject({ currency: 'JPY' });
|
||||
expect(await canAccessTrip(tripId, member)).toMatchObject({ currency: 'JPY' });
|
||||
});
|
||||
|
||||
it('returns undefined for a user with no access', () => {
|
||||
it('returns undefined for a user with no access', async () => {
|
||||
const owner = seedUser('owner3');
|
||||
const stranger = seedUser('stranger3');
|
||||
const tripId = Number(
|
||||
db.prepare("INSERT INTO trips (user_id, title) VALUES (?, 'Trip')").run(owner).lastInsertRowid,
|
||||
);
|
||||
|
||||
expect(canAccessTrip(tripId, stranger)).toBeUndefined();
|
||||
expect(await canAccessTrip(tripId, stranger)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,7 +59,7 @@ describe('canAccessTrip', () => {
|
||||
* regression the block above pins was invisible to the suites that mock the db.
|
||||
*/
|
||||
describe('the buildDbMock stand-in for canAccessTrip', () => {
|
||||
it('hands back the trip currency, like the real one', () => {
|
||||
it('hands back the trip currency, like the real one', async () => {
|
||||
const testDb = createTestDb();
|
||||
try {
|
||||
const owner = Number(
|
||||
@@ -71,7 +71,7 @@ describe('the buildDbMock stand-in for canAccessTrip', () => {
|
||||
.run(owner).lastInsertRowid,
|
||||
);
|
||||
|
||||
expect(buildDbMock(testDb).canAccessTrip(tripId, owner)).toMatchObject({ id: tripId, currency: 'ISK' });
|
||||
expect(await buildDbMock(testDb).canAccessTrip(tripId, owner)).toMatchObject({ id: tripId, currency: 'ISK' });
|
||||
} finally {
|
||||
testDb.close();
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ describe('DatabaseService (helper delegation)', () => {
|
||||
const { db } = await import('../../../src/db/database');
|
||||
const svc = new DatabaseService(db);
|
||||
|
||||
expect(svc.canAccessTrip(7, 8)).toEqual({ id: -1, user_id: -2, currency: 'XXX' });
|
||||
expect(await svc.canAccessTrip(7, 8)).toEqual({ id: -1, user_id: -2, currency: 'XXX' });
|
||||
expect(canAccessTrip).toHaveBeenCalledWith(7, 8);
|
||||
|
||||
expect(svc.isOwner(7, 8)).toBe(true);
|
||||
expect(await svc.isOwner(7, 8)).toBe(true);
|
||||
expect(isOwner).toHaveBeenCalledWith(7, 8);
|
||||
|
||||
expect(svc.getPlaceWithTags(9)).toBeNull();
|
||||
expect(await svc.getPlaceWithTags(9)).toBeNull();
|
||||
expect(getPlaceWithTags).toHaveBeenCalledWith(9);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('DatabaseService (typed query helpers)', () => {
|
||||
describe('DatabaseService (trip-access helpers)', () => {
|
||||
const svc = new DatabaseService(db);
|
||||
|
||||
it('canAccessTrip / isOwner / getPlaceWithTags delegate to the shared helpers', () => {
|
||||
it('canAccessTrip / isOwner / getPlaceWithTags delegate to the shared helpers', async () => {
|
||||
svc.run(
|
||||
"INSERT INTO users (id, username, email, password_hash) VALUES (900, 'dbsvc-owner', 'dbsvc-owner@x.test', 'x')"
|
||||
);
|
||||
@@ -46,16 +46,16 @@ describe('DatabaseService (trip-access helpers)', () => {
|
||||
svc.run("INSERT INTO trips (id, user_id, title) VALUES (900, 900, 'DbSvc Trip')");
|
||||
svc.run("INSERT INTO trip_members (trip_id, user_id) VALUES (900, 901)");
|
||||
|
||||
expect(svc.canAccessTrip(900, 900)).toMatchObject({ id: 900, user_id: 900 });
|
||||
expect(svc.canAccessTrip(900, 901)).toMatchObject({ id: 900 });
|
||||
expect(svc.canAccessTrip(900, 999)).toBeUndefined();
|
||||
expect(await svc.canAccessTrip(900, 900)).toMatchObject({ id: 900, user_id: 900 });
|
||||
expect(await svc.canAccessTrip(900, 901)).toMatchObject({ id: 900 });
|
||||
expect(await svc.canAccessTrip(900, 999)).toBeUndefined();
|
||||
|
||||
expect(svc.isOwner(900, 900)).toBe(true);
|
||||
expect(svc.isOwner(900, 901)).toBe(false);
|
||||
expect(await svc.isOwner(900, 900)).toBe(true);
|
||||
expect(await svc.isOwner(900, 901)).toBe(false);
|
||||
|
||||
expect(svc.getPlaceWithTags(999999)).toBeNull();
|
||||
expect(await svc.getPlaceWithTags(999999)).toBeNull();
|
||||
svc.run("INSERT INTO places (id, trip_id, name) VALUES (900, 900, 'DbSvc Place')");
|
||||
expect(svc.getPlaceWithTags(900)).toMatchObject({
|
||||
expect(await svc.getPlaceWithTags(900)).toMatchObject({
|
||||
id: 900,
|
||||
name: 'DbSvc Place',
|
||||
category: null,
|
||||
|
||||
Reference in New Issue
Block a user