Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
# Basic set up for three package managers

version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
- directory: /
package-ecosystem: "npm"
schedule:
interval: "weekly"
time: "18:00" # UTC, = ~10AM Pacific
groups:
major:
update-types:
- major
minor:
update-types:
- minor
- patch

- directory: /
package-ecosystem: "github-actions"
schedule:
interval: "weekly"
time: "18:00" # UTC, = ~10AM Pacific
groups:
major:
update-types:
- major
minor:
update-types:
- minor
- patch

# Maintain dependencies for Docker
- package-ecosystem: "composer"
directory: "/"
- directory: /
package-ecosystem: "docker"
schedule:
interval: "weekly"
time: "18:00" # UTC, = ~10AM Pacific
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22
26
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:22-alpine
FROM node:26-alpine

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
Expand Down
3 changes: 2 additions & 1 deletion api/admin/routes/add-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ process.env.GITHUB_CLIENT_ID = 'test-client-id';
process.env.GITHUB_CLIENT_SECRET = 'test-client-secret';
process.env.ADMIN_SESSION_SECRET = 'test-session-secret-for-testing-only';

import { afterAll, beforeEach, describe, expect, it } from '@jest/globals';
import express from 'express';
import { resolve } from 'node:path';
import { makeFetch } from 'supertest-fetch';
Expand Down Expand Up @@ -83,7 +84,7 @@ async function expectAppInDatabase(
'SELECT * FROM apps WHERE id = $1',
[appId],
);
expect(result.rows.length).toBe(1);
expect(result.rows).toHaveLength(1);
expect(result.rows[0].bungie_api_key).toBe(expectedData.bungieApiKey);
expect(result.rows[0].origin).toBe(expectedData.origin);
}
Expand Down
1 change: 1 addition & 0 deletions api/admin/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ process.env.GITHUB_CLIENT_ID = 'test-client-id';
process.env.GITHUB_CLIENT_SECRET = 'test-client-secret';
process.env.ADMIN_SESSION_SECRET = 'test-session-secret-for-testing-only';

import { afterAll, beforeEach, describe, expect, it } from '@jest/globals';
import { makeFetch } from 'supertest-fetch';
import { closeDbPool, pool } from '../db/index.js';
import { app } from '../server.js';
Expand Down
5 changes: 3 additions & 2 deletions api/db/apps-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DatabaseError } from 'pg-protocol';
import { afterAll, beforeEach, expect, it } from '@jest/globals';
import { DatabaseError } from 'pg';
import { v4 as uuid } from 'uuid';
import { ApiApp } from '../shapes/app.js';
import { getAllApps, getAppById, insertApp } from './apps-queries.js';
Expand Down Expand Up @@ -34,7 +35,7 @@ it('cannot create a new app with the same name as an existing one', async () =>
await insertApp(client, app);
} catch (e) {
if (!(e instanceof DatabaseError)) {
fail('should have thrown a DatabaseError');
throw new Error('should have thrown a DatabaseError', { cause: e });
}
expect(e.code).toBe('23505');
}
Expand Down
7 changes: 4 additions & 3 deletions api/db/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, beforeEach, describe, expect, it } from '@jest/globals';
import { closeDbPool, pool, readTransaction, transaction } from './index.js';

beforeEach(async () => {
Expand Down Expand Up @@ -31,13 +32,13 @@ describe('transaction', () => {
await client.query("insert into transaction_test (id, test) values (2, 'testing')");
throw new Error('oops');
});
fail('should have thrown an error');
throw new Error('should have thrown an error');
} catch (e) {
expect((e as Error).message).toBe('oops');
}

const result = await pool.query<TransactionTestRow>('select * from transaction_test');
expect(result.rows.length).toBe(1);
expect(result.rows).toHaveLength(1);
expect(result.rows[0].id).toBe(1);
});

Expand All @@ -47,7 +48,7 @@ describe('transaction', () => {
});

const result = await pool.query<TransactionTestRow>('select * from transaction_test');
expect(result.rows.length).toBe(1);
expect(result.rows).toHaveLength(1);
expect(result.rows[0].test).toBe('testing commits');
});
});
Expand Down
1 change: 1 addition & 0 deletions api/db/item-annotations-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, beforeEach, expect, it } from '@jest/globals';
import { closeDbPool, transaction } from './index.js';
import {
deleteAllItemAnnotations,
Expand Down
1 change: 1 addition & 0 deletions api/db/item-hash-tags-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, beforeEach, expect, it } from '@jest/globals';
import { closeDbPool, transaction } from './index.js';
import {
deleteAllItemHashTags,
Expand Down
4 changes: 3 additions & 1 deletion api/db/loadout-share-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, beforeEach, expect, it } from '@jest/globals';
import { v4 as uuid } from 'uuid';
import { Loadout, LoadoutItem } from '../shapes/loadouts.js';
import { closeDbPool, transaction } from './index.js';
Expand Down Expand Up @@ -48,13 +49,14 @@ it('can record a shared loadout', async () => {
});
});


it('rejects multiple shares with the same ID', async () => {
await transaction(async (client) => {
await addLoadoutShare(client, bungieMembershipId, platformMembershipId, shareID, loadout);

try {
await addLoadoutShare(client, bungieMembershipId, platformMembershipId, shareID, loadout);
fail('Expected this to throw an error');
throw new Error('Expected this to throw an error');
} catch {}
});
});
Expand Down
17 changes: 9 additions & 8 deletions api/db/loadouts-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, beforeEach, expect, it } from '@jest/globals';
import { v4 as uuid } from 'uuid';
import { Loadout, LoadoutItem } from '../shapes/loadouts.js';
import { closeDbPool, transaction } from './index.js';
Expand Down Expand Up @@ -52,14 +53,14 @@ it('can record a loadout', async () => {

const loadouts = await getLoadoutsForProfile(client, platformMembershipId, 2);

expect(loadouts.length).toBe(1);
expect(loadouts).toHaveLength(1);

const firstLoadout = loadouts[0];
expect(firstLoadout.createdAt).toBeDefined();
delete firstLoadout.createdAt;
expect(firstLoadout.lastUpdatedAt).toBeDefined();
delete firstLoadout.lastUpdatedAt;
expect(firstLoadout.unequipped.length).toBe(1);
expect(firstLoadout.unequipped).toHaveLength(1);
expect((firstLoadout.unequipped[0] as { fizbuzz?: number }).fizbuzz).toBeUndefined();
(firstLoadout.unequipped[0] as { fizbuzz?: number }).fizbuzz = 11;
expect(firstLoadout).toEqual(loadout);
Expand All @@ -78,9 +79,9 @@ it('can update a loadout', async () => {

const loadouts = await getLoadoutsForProfile(client, platformMembershipId, 2);

expect(loadouts.length).toBe(1);
expect(loadouts).toHaveLength(1);
expect(loadouts[0].name).toEqual('Updated');
expect(loadouts[0].unequipped.length).toBe(0);
expect(loadouts[0].unequipped).toHaveLength(0);
expect(loadouts[0].equipped).toEqual(loadout.equipped);
});
});
Expand All @@ -94,25 +95,25 @@ it('can delete a loadout', async () => {

const loadouts = await getLoadoutsForProfile(client, platformMembershipId, 2);

expect(loadouts.length).toBe(0);
expect(loadouts).toHaveLength(0);
});
});

it('can soft-delete all loadouts for a platform and destiny version', async () => {
await transaction(async (client) => {
await updateLoadout(client, bungieMembershipId, platformMembershipId, 2, loadout);
const loadouts = await getLoadoutsForProfile(client, platformMembershipId, 2);
expect(loadouts.length).toBe(1);
expect(loadouts).toHaveLength(1);

await softDeleteAllLoadouts(client, platformMembershipId, 2);

// D2 loadouts should be gone
const loadoutsDeleted = await getLoadoutsForProfile(client, platformMembershipId, 2);
expect(loadoutsDeleted.length).toBe(0);
expect(loadoutsDeleted).toHaveLength(0);

// Recreate the loadout
await updateLoadout(client, bungieMembershipId, platformMembershipId, 2, loadout);
const loadoutsAfter = await getLoadoutsForProfile(client, platformMembershipId, 2);
expect(loadoutsAfter.length).toBe(1);
expect(loadoutsAfter).toHaveLength(1);
});
});
9 changes: 5 additions & 4 deletions api/db/searches-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, beforeEach, expect, it } from '@jest/globals';
import { SearchType } from '../shapes/search.js';
import { closeDbPool, transaction } from './index.js';
import {
Expand Down Expand Up @@ -150,7 +151,7 @@ it('can delete a search', async () => {
const searches = (await getSearchesForProfile(client, platformMembershipId, 2)).filter(
(s) => s.usageCount > 0,
);
expect(searches.length).toBe(0);
expect(searches).toHaveLength(0);
});
});

Expand Down Expand Up @@ -210,14 +211,14 @@ it('can soft delete all searches', async () => {
);

const searches = await getSearchesForProfile(client, platformMembershipId, 2);
expect(searches.length).toBe(1);
expect(searches).toHaveLength(1);

// Soft delete all searches
await softDeleteAllSearches(client, platformMembershipId, 2);

// Verify searches are soft deleted (usageCount = 0)
const searchesAfter = await getSearchesForProfile(client, platformMembershipId, 2);
expect(searchesAfter.length).toBe(0);
expect(searchesAfter).toHaveLength(0);

// Now re-use the same search - this should succeed and not create a duplicate
await updateUsedSearch(
Expand All @@ -230,7 +231,7 @@ it('can soft delete all searches', async () => {
);

const searchesAfter2 = await getSearchesForProfile(client, platformMembershipId, 2);
expect(searchesAfter2.length).toBe(1);
expect(searchesAfter2).toHaveLength(1);
expect(searchesAfter2[0].query).toBe('is:weapon');
expect(searchesAfter2[0].usageCount).toBe(1);
});
Expand Down
1 change: 1 addition & 0 deletions api/db/settings-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, expect, it } from '@jest/globals';
import { closeDbPool, transaction } from './index.js';
import { getSettings, setSetting } from './settings-queries.js';

Expand Down
5 changes: 3 additions & 2 deletions api/db/triumphs-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, beforeEach, expect, it } from '@jest/globals';
import { closeDbPool, transaction } from './index.js';
import {
deleteAllTrackedTriumphs,
Expand Down Expand Up @@ -45,7 +46,7 @@ it('can untrack a triumph', async () => {
await unTrackTriumph(client, platformMembershipId, 3851137658);

const triumphs = await getTrackedTriumphsForProfile(client, platformMembershipId);
expect(triumphs.length).toEqual(0);
expect(triumphs).toHaveLength(0);
});
});

Expand All @@ -57,7 +58,7 @@ it('handles soft delete correctly', async () => {
await softDeleteAllTrackedTriumphs(client, platformMembershipId);

const triumphs = await getTrackedTriumphsForProfile(client, platformMembershipId);
expect(triumphs.length).toBe(0);
expect(triumphs).toHaveLength(0);

// Now re-track the same triumph - this should succeed and not create a duplicate
await trackTriumph(client, bungieMembershipId, platformMembershipId, 3851137658);
Expand Down
8 changes: 7 additions & 1 deletion api/dim-gg/loadout-share-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import { loadLoadoutShare } from '../routes/loadout-share.js';
/**
* Save a loadout to be shared via a dim.gg link.
*/
export const loadoutShareViewHandler = asyncHandler(async (req, res) => {
export const loadoutShareViewHandler = asyncHandler(async (req, res, next) => {
const { shareId } = req.params;
// Express 5 routes can't contain inline regexes, so validate the share ID
// here and fall through to other handlers (e.g. static files) if it doesn't match.
if (typeof shareId !== 'string' || !/^[a-z0-9]{7}$/.test(shareId)) {
next();
return;
}

const loadout = await loadLoadoutShare(shareId);

Expand Down
3 changes: 2 additions & 1 deletion api/dim-gg/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const app = express();

app.set('view engine', 'ejs');
app.set('views', './api/dim-gg/views');
app.disable('x-powered-by');

app.use(expressStatsd({ client: metrics, prefix: 'dimgg' })); // metrics
app.use(express.json({ limit: '2mb' })); // for parsing application/json
Expand All @@ -22,7 +23,7 @@ app.get('/', (_req, res) => {
});

// Loadout share preview/landing pages
app.get('/:shareId([a-z0-9]{7})/:titleSlug?', loadoutShareViewHandler);
app.get('/:shareId{/:titleSlug}', loadoutShareViewHandler);

// Serve static files (images, JS, etc from the dim-gg-static folder
// TODO: uniquely name these and then serve them with Cache-Control: Immutable
Expand Down
Loading