Skip to content

Commit

Permalink
Create test for dependency-discovery service
Browse files Browse the repository at this point in the history
  • Loading branch information
TueeNguyen committed Feb 14, 2022
1 parent e720097 commit b6967fb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/api/dependency-discovery/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const baseConfig = require('../../../jest.config.base');

module.exports = {
...baseConfig,
setupFiles: ['<rootDir>/src/api/dependency-discovery/jest.setup.js'],
rootDir: '../../..',
testMatch: ['<rootDir>/src/api/dependency-discovery/test/*.test.js'],
collectCoverageFrom: ['<rootDir>/src.api/dependency-discovery/src/**/*.js'],
};
1 change: 1 addition & 0 deletions src/api/dependency-discovery/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.env = { ...process.env };
1 change: 0 additions & 1 deletion src/api/dependency-discovery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "0.1.0",
"description": "A dependency graph compilation service for Telescope",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/server.js",
"dev": "env-cmd -f env.local nodemon src/server.js"
},
Expand Down
2 changes: 1 addition & 1 deletion src/api/dependency-discovery/src/dependency-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ async function getDependencies() {
return dependencies.split(/\r\n|\n|\r/).filter((line) => line !== '');
}

module.exports = getDependencies();
module.exports = getDependencies;
4 changes: 2 additions & 2 deletions src/api/dependency-discovery/src/router.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { Router } = require('@senecacdot/satellite');
const dependencyList = require('./dependency-list');
const getDependencies = require('./dependency-list');

const router = Router();

router.get('/projects', async (req, res, next) => {
try {
res.set('Cache-Control', 'max-age=3600');
res.status(200).json(await dependencyList);
res.status(200).json(await getDependencies());
} catch (err) {
next(err);
}
Expand Down
29 changes: 29 additions & 0 deletions src/api/dependency-discovery/test/dependency.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const request = require('supertest');
const { app } = require('../src');

const depsList = [
'@apidevtools/json-schema-ref-parser',
'@babel/code-frame',
'@babel/compat-data',
'@babel/core", "@babel/generator',
'@babel/helper-annotate-as-pure',
'@babel/helper-builder-binary-assignment-operator-visitor',
'@babel/helper-compilation-targets',
'@babel/helper-create-class-features-plugin',
'@babel/helper-create-regexp-features-plugin',
];

jest.mock('../src/dependency-list', () => {
return jest.fn().mockImplementation(() => {
return Promise.resolve(depsList);
});
});

describe('GET /projects', () => {
test('Should return 200 and an array of dependencies', async () => {
const res = await request(app).get('/projects');
expect(res.status).toBe(200);
expect(typeof res.body).toEqual('object');
expect(res.body.length).toBe(depsList.length);
});
});

0 comments on commit b6967fb

Please sign in to comment.