test(catalog/gql): added some tests as i couldn't get codecov to ignore
This commit is contained in:
@@ -6,7 +6,3 @@ coverage:
|
||||
default:
|
||||
threshold: 0% # Ref: https://docs.codecov.io/docs/codecovyml-reference#coveragestatus
|
||||
target: auto
|
||||
|
||||
ignore:
|
||||
- './src/plugins/*-graphql/**/*'
|
||||
- './src/plugins/graphql/*'
|
||||
|
||||
@@ -14,10 +14,46 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { CatalogClient } from './client';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
|
||||
describe('Catalog GraphQL Module', () => {
|
||||
it('create a new client', () => {
|
||||
void new CatalogClient('http://localhost:1234');
|
||||
expect(true).toBe(true);
|
||||
const worker = setupServer();
|
||||
|
||||
beforeAll(() => worker.listen());
|
||||
afterAll(() => worker.close());
|
||||
|
||||
afterEach(() => worker.resetHandlers());
|
||||
|
||||
const baseUrl = 'http://localhost:1234';
|
||||
|
||||
it('will return the entities', async () => {
|
||||
const expectedResponse = [{ id: 'something' }];
|
||||
|
||||
worker.use(
|
||||
rest.get(`${baseUrl}/catalog/entities`, (_, res, ctx) =>
|
||||
res(ctx.status(200), ctx.json(expectedResponse)),
|
||||
),
|
||||
);
|
||||
|
||||
const client = new CatalogClient(baseUrl);
|
||||
|
||||
const response = await client.list();
|
||||
|
||||
expect(response).toEqual(expectedResponse);
|
||||
});
|
||||
|
||||
it('throws an error with the text', async () => {
|
||||
const expectedResponse = 'something broke';
|
||||
|
||||
worker.use(
|
||||
rest.get(`${baseUrl}/catalog/entities`, (_, res, ctx) =>
|
||||
res(ctx.status(500), ctx.text(expectedResponse)),
|
||||
),
|
||||
);
|
||||
|
||||
const client = new CatalogClient(baseUrl);
|
||||
|
||||
await expect(() => client.list()).rejects.toThrow(expectedResponse);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,10 +13,25 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import './router';
|
||||
import { createRouter } from './router';
|
||||
import supertest from 'supertest';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { createLogger } from 'winston';
|
||||
import express from 'express';
|
||||
|
||||
describe('Router', () => {
|
||||
it('should pass the test', () => {
|
||||
expect(true).toBeTruthy();
|
||||
describe('/health', () => {
|
||||
it('should return ok', async () => {
|
||||
const config = ConfigReader.fromConfigs([
|
||||
{ data: { backend: { baseUrl: 'lol' } }, context: 'something' },
|
||||
]);
|
||||
|
||||
const router = await createRouter({ config, logger: createLogger() });
|
||||
const app = express().use(router);
|
||||
|
||||
const { body } = await supertest(app).get('/health');
|
||||
|
||||
expect(body).toEqual({ status: 'ok' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -56,7 +56,11 @@ export async function createRouter(
|
||||
|
||||
const router = Router();
|
||||
|
||||
const apolloMiddlware = server.getMiddleware({ path: '/' });
|
||||
router.get('/health', (_, response) => {
|
||||
response.send({ status: 'ok' });
|
||||
});
|
||||
|
||||
const apolloMiddleware = server.getMiddleware({ path: '/' });
|
||||
|
||||
if (process.env.NODE_ENV === 'development')
|
||||
router.use(
|
||||
@@ -67,11 +71,7 @@ export async function createRouter(
|
||||
}),
|
||||
);
|
||||
|
||||
router.use(apolloMiddlware);
|
||||
|
||||
router.get('/health', (_, response) => {
|
||||
response.send({ status: 'ok' });
|
||||
});
|
||||
router.use(apolloMiddleware);
|
||||
|
||||
router.use(errorHandler());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user