diff --git a/.codecov.yml b/.codecov.yml index 476807cd7e..bbe2ee8e93 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -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/*' diff --git a/plugins/catalog-graphql/src/service/client.test.ts b/plugins/catalog-graphql/src/service/client.test.ts index e249bf1c15..876059802b 100644 --- a/plugins/catalog-graphql/src/service/client.test.ts +++ b/plugins/catalog-graphql/src/service/client.test.ts @@ -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); }); }); diff --git a/plugins/graphql/src/service/router.test.ts b/plugins/graphql/src/service/router.test.ts index 30bcb8e25d..983fbbb761 100644 --- a/plugins/graphql/src/service/router.test.ts +++ b/plugins/graphql/src/service/router.test.ts @@ -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' }); + }); }); }); diff --git a/plugins/graphql/src/service/router.ts b/plugins/graphql/src/service/router.ts index 4be2a43733..32607d72b1 100644 --- a/plugins/graphql/src/service/router.ts +++ b/plugins/graphql/src/service/router.ts @@ -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());