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
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions tests/boot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } }],
Expand All @@ -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',
Expand All @@ -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' } }],
Expand All @@ -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');
Expand All @@ -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' }] });

Expand All @@ -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' });

Expand All @@ -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');
Expand Down
16 changes: 8 additions & 8 deletions tests/routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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' }]);
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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' }] }] });
Expand All @@ -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', {
Expand All @@ -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', {
Expand Down
Loading