Skip to content

Commit

Permalink
add unit test for routes
Browse files Browse the repository at this point in the history
Issue: BB-538
  • Loading branch information
benzekrimaha committed Nov 6, 2024
1 parent c1860dc commit 6240441
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions tests/unit/api/routes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
const assert = require('assert');
const routes = require('../../../lib/api/routes');

describe('routes', () => {
it('should generate the correct routes with default locations', () => {
const locations = {
crr: ['site1', 'site2'],
ingestion: ['site3'],
lifecycle: ['site4'],
};
const disableAdditionalRoutes = false;
const result = routes(locations, disableAdditionalRoutes);

assert.strictEqual(result.length, 19);

assert.deepStrictEqual(result[0], {
httpMethod: 'GET',
category: 'healthcheck',
type: 'basic',
method: 'getHealthcheck',
extensions: {},
});

assert.deepStrictEqual(result[1], {
httpMethod: 'GET',
category: 'metrics',
type: 'backlog',
extensions: { crr: ['site1', 'site2', 'all'] },
method: 'getBacklog',
dataPoints: ['opsPending', 'bytesPending'],
});

assert.deepStrictEqual(result[2], {
httpMethod: 'GET',
category: 'metrics',
type: 'completions',
extensions: {
crr: ['site1', 'site2', 'all'],
ingestion: ['site3', 'all'],
},
method: 'getCompletions',
dataPoints: ['opsDone', 'bytesDone'],
});
});

it('should generate the correct routes with additional routes disabled', () => {
const locations = {
crr: ['site1', 'site2'],
ingestion: ['site3'],
lifecycle: ['site4'],
};
const disableAdditionalRoutes = true;
const result = routes(locations, disableAdditionalRoutes);

assert.strictEqual(result.length, 8);
assert.deepStrictEqual(result[0], {
httpMethod: 'GET',
category: 'healthcheck',
type: 'basic',
method: 'getHealthcheck',
extensions: {},
});

assert.deepStrictEqual(result[1], {
httpMethod: 'GET',
category: 'metrics',
type: 'backlog',
extensions: { crr: ['site1', 'site2', 'all'] },
method: 'getBacklog',
dataPoints: ['opsPending', 'bytesPending'],
});

assert.deepStrictEqual(result[2], {
httpMethod: 'GET',
category: 'metrics',
type: 'completions',
extensions: {
crr: ['site1', 'site2', 'all'],
ingestion: ['site3', 'all'],
},
method: 'getCompletions',
dataPoints: ['opsDone', 'bytesDone'],
});
});

it('should handle empty locations', () => {
const locations = {};
const disableAdditionalRoutes = false;
const result = routes(locations, disableAdditionalRoutes);

assert.strictEqual(result.length, 19);

assert.deepStrictEqual(result[0], {
httpMethod: 'GET',
category: 'healthcheck',
type: 'basic',
method: 'getHealthcheck',
extensions: {},
});

assert.deepStrictEqual(result[1], {
httpMethod: 'GET',
category: 'metrics',
type: 'backlog',
extensions: { crr: ['all'] },
method: 'getBacklog',
dataPoints: ['opsPending', 'bytesPending'],
});

assert.deepStrictEqual(result[2], {
httpMethod: 'GET',
category: 'metrics',
type: 'completions',
extensions: {
crr: ['all'],
ingestion: ['all'],
},
method: 'getCompletions',
dataPoints: ['opsDone', 'bytesDone'],
});

});
});

0 comments on commit 6240441

Please sign in to comment.