diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ba034d7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,16 @@ +name: Test + +on: + push: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + - run: npm ci + - run: npm test diff --git a/tests/boot.test.js b/tests/boot.test.js index 037b9e1..fed9800 100644 --- a/tests/boot.test.js +++ b/tests/boot.test.js @@ -20,7 +20,7 @@ describe('ensureUser', () => { }); test('uses existing user if one is found', async () => { - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .get('/organizations/test-org/users?token=test-token') .reply(200, { users: [{ id: 'user-abc', uid: 'sample-user', marketplace: { token: 'token-xyz', url: 'https://marketplace.validic.com?token=token-xyz' } }], @@ -33,11 +33,11 @@ describe('ensureUser', () => { }); test('provisions new user if org has no users', async () => { - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .get('/organizations/test-org/users?token=test-token') .reply(200, { users: [] }); - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .post('/organizations/test-org/users?token=test-token') .reply(201, { id: 'user-new', @@ -54,7 +54,7 @@ describe('ensureUser', () => { test('always calls API even if VALIDIC_USER_ID set in env', async () => { process.env.VALIDIC_USER_ID = 'stale-env-user'; - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .get('/organizations/test-org/users?token=test-token') .reply(200, { users: [{ id: 'api-user', uid: 'real-user', marketplace: { token: 'tok', url: 'https://marketplace.validic.com?token=tok' } }], @@ -65,7 +65,7 @@ describe('ensureUser', () => { }); test('throws on Validic API error', async () => { - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .get('/organizations/test-org/users?token=test-token') .reply(401, 'Unauthorized'); await expect(ensureUser()).rejects.toThrow('Failed to list users: 401'); @@ -80,7 +80,7 @@ describe('ensureStream', () => { }); test('uses existing stream if found', async () => { - nock('https://streams.staging.validic.com') + nock('https://streams.v2.validic.com') .get('/streams?token=test-token') .reply(200, { streams: [{ id: 'stream-existing', name: 'sample-app-stream' }] }); @@ -90,11 +90,11 @@ describe('ensureStream', () => { }); test('creates stream if none found', async () => { - nock('https://streams.staging.validic.com') + nock('https://streams.v2.validic.com') .get('/streams?token=test-token') .reply(200, { streams: [] }); - nock('https://streams.staging.validic.com') + nock('https://streams.v2.validic.com') .post('/streams?token=test-token') .reply(201, { id: 'stream-123', name: 'sample-app-stream' }); @@ -104,7 +104,7 @@ describe('ensureStream', () => { }); test('throws on Validic API error', async () => { - nock('https://streams.staging.validic.com') + nock('https://streams.v2.validic.com') .get('/streams?token=test-token') .reply(500, 'internal error'); await expect(ensureStream()).rejects.toThrow('Failed to list streams: 500'); diff --git a/tests/routes.test.js b/tests/routes.test.js index 8d3ca17..5e54654 100644 --- a/tests/routes.test.js +++ b/tests/routes.test.js @@ -5,7 +5,7 @@ const nock = require('nock'); process.env.ORG_ID = 'test-org'; process.env.ORG_TOKEN = 'test-token'; process.env.VALIDIC_USER_ID = 'user-uid-abc'; -process.env.VALIDIC_MARKETPLACE_URL = 'https://marketplace.staging.validic.com?token=token-xyz'; +process.env.VALIDIC_MARKETPLACE_URL = 'https://marketplace.v2.validic.com?token=token-xyz'; process.env.VALIDIC_STREAM_ID = 'stream-123'; nock.disableNetConnect(); @@ -25,14 +25,14 @@ describe('GET /api/status', () => { user_id: 'user-uid-abc', stream_id: 'stream-123', provisioned: true, - marketplace_url: 'https://marketplace.staging.validic.com?token=token-xyz', + marketplace_url: 'https://marketplace.v2.validic.com?token=token-xyz', }); }); }); describe('GET /api/apps', () => { test('returns apps from Validic API', async () => { - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .get('/organizations/test-org/users/user-uid-abc/apps') .query({ token: 'test-token' }) .reply(200, [{ name: 'Fitbit', synced: true, last_sync: '2024-01-01T00:00:00Z' }]); @@ -43,7 +43,7 @@ describe('GET /api/apps', () => { }); test('returns 500 on Validic API failure', async () => { - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .get('/organizations/test-org/users/user-uid-abc/apps') .query(true) .replyWithError('network error'); @@ -53,7 +53,7 @@ describe('GET /api/apps', () => { }); test('forwards non-2xx HTTP status from Validic API', async () => { - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .get('/organizations/test-org/users/user-uid-abc/apps') .query(true) .reply(404, 'Not Found'); @@ -66,7 +66,7 @@ describe('GET /api/apps', () => { describe('GET /api/data/:type', () => { test('returns last 30 days of data for valid type', async () => { - nock('https://api.staging.validic.com') + nock('https://api.v2.validic.com') .get('/organizations/test-org/users/user-uid-abc/summaries') .query(true) .reply(200, { data: [{ id: 'rec-1', type: 'summary', metrics: [{ type: 'steps', value: 8000, unit: 'count' }] }] }); @@ -90,7 +90,7 @@ describe('GET /api/data/:type', () => { describe('GET /api/stream/connect', () => { test('responds with text/event-stream content-type', (done) => { - nock('https://streams.staging.validic.com') + nock('https://streams.v2.validic.com') .get('/streams/stream-123/connect') .query({ token: 'test-token' }) .reply(200, 'event: data\ndata: {"type":"summary"}\n\n', { @@ -109,7 +109,7 @@ describe('GET /api/stream/connect', () => { describe('GET /api/stream/replay', () => { test('responds with text/event-stream content-type', (done) => { - nock('https://streams.staging.validic.com') + nock('https://streams.v2.validic.com') .get('/replay') .query(true) .reply(200, 'event: data\ndata: {"type":"measurement"}\n\n', {