-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding
test/nodeEnvSetupFile.js
for Jest configuration
Adding ApiContainer tests
- Loading branch information
Showing
7 changed files
with
72 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/falcon-server/src/containers/ApiContainer.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const ApiContainer = require('./ApiContainer'); | ||
|
||
const apis = [{ package: 'fake-backend-api', name: 'fake-api' }]; | ||
|
||
describe('ApiContainer', () => { | ||
it('Should register provided API DataSources', () => { | ||
/** @type {ApiContainer} */ | ||
const container = new ApiContainer(apis); | ||
expect(container.dataSources.size).toBe(1); | ||
expect(container.endpoints).toHaveLength(1); | ||
|
||
const apiInstance = container.dataSources.get('fake-api'); | ||
expect(apiInstance).toBeTruthy(); | ||
expect(apiInstance.name).toBe('fake-api'); | ||
|
||
const endpoint = container.endpoints[0]; | ||
expect(endpoint.path).toBe('/api/info'); | ||
}); | ||
|
||
it('Should do nothing for an empty API list', () => { | ||
const container = new ApiContainer(); | ||
expect(container.dataSources.size).toBe(0); | ||
expect(container.endpoints).toHaveLength(0); | ||
}); | ||
|
||
it('Should not fail for missing API DataSource package', () => { | ||
const container = new ApiContainer([{ package: 'foo-bar' }]); | ||
|
||
expect(container.dataSources.size).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/falcon-server/src/containers/__mocks__/fake-backend-api/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { ApiDataSource } = require('@deity/falcon-server-env'); | ||
|
||
module.exports = class FakeBackendApi extends ApiDataSource { | ||
getEndpoints() { | ||
return [ | ||
{ | ||
path: '/api/info', | ||
methods: ['get'], | ||
handler: () => {} | ||
} | ||
]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// eslint-disable-next-line no-underscore-dangle | ||
global.__SERVER__ = true; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const Logger = require('@deity/falcon-logger'); | ||
|
||
// disable logger for tests | ||
Logger.setLogLevel('error'); |