Added production-api.test.ts
Signed-off-by: Karan Shah <karan.shah@simplybusiness.co.uk>
This commit is contained in:
@@ -28,14 +28,13 @@
|
||||
"@material-ui/core": "^4.12.2",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@material-ui/lab": "4.0.0-alpha.57",
|
||||
"react-use": "^17.2.4",
|
||||
"object-hash": "^2.2.0"
|
||||
"object-hash": "^2.2.0",
|
||||
"react-use": "^17.2.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.13.1 || ^17.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/object-hash": "^2.2.1",
|
||||
"@backstage/app-defaults": "^0.1.6",
|
||||
"@backstage/cli": "^0.13.1",
|
||||
"@backstage/core-app-api": "^0.5.2",
|
||||
@@ -46,8 +45,10 @@
|
||||
"@testing-library/user-event": "^13.1.8",
|
||||
"@types/jest": "^26.0.7",
|
||||
"@types/node": "^14.14.32",
|
||||
"msw": "^0.35.0",
|
||||
"@types/object-hash": "^2.2.1",
|
||||
"cross-fetch": "^3.0.6",
|
||||
"msw": "^0.35.0",
|
||||
"nock": "^13.2.4",
|
||||
"react-router": "6.0.0-beta.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ProductionAirbrakeApi } from './production-api';
|
||||
import nock from 'nock';
|
||||
import mockGroupsData from './mock/airbrake-groups-api-mock.json';
|
||||
|
||||
describe('The production Airbrake API', () => {
|
||||
let productionApi: ProductionAirbrakeApi;
|
||||
|
||||
beforeEach(() => {
|
||||
productionApi = new ProductionAirbrakeApi('fakeApiKey');
|
||||
});
|
||||
|
||||
it('fetches groups using the provided project ID', async () => {
|
||||
const scope = nock('https://api.airbrake.io')
|
||||
.get('/api/v4/projects/123456/groups?key=fakeApiKey')
|
||||
.reply(200, mockGroupsData);
|
||||
expect(scope.isDone()).toBe(false);
|
||||
|
||||
const groups = await productionApi.fetchGroups('123456');
|
||||
|
||||
expect(scope.isDone()).toBe(true);
|
||||
expect(groups).toStrictEqual(mockGroupsData);
|
||||
});
|
||||
|
||||
it('throws if fetching groups was unsuccessful', async () => {
|
||||
const scope = nock('https://api.airbrake.io')
|
||||
.get('/api/v4/projects/123456/groups?key=fakeApiKey')
|
||||
.reply(500, mockGroupsData);
|
||||
expect(scope.isDone()).toBe(false);
|
||||
|
||||
await expect(productionApi.fetchGroups('123456')).rejects.toThrow();
|
||||
|
||||
expect(scope.isDone()).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -16155,6 +16155,11 @@ lodash.once@^4.0.0, lodash.once@^4.1.1:
|
||||
resolved "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"
|
||||
integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=
|
||||
|
||||
lodash.set@^4.3.2:
|
||||
version "4.3.2"
|
||||
resolved "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
|
||||
integrity sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=
|
||||
|
||||
lodash.sortby@^4.7.0:
|
||||
version "4.7.0"
|
||||
resolved "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
|
||||
@@ -17658,6 +17663,16 @@ no-case@^3.0.4:
|
||||
lower-case "^2.0.2"
|
||||
tslib "^2.0.3"
|
||||
|
||||
nock@^13.2.4:
|
||||
version "13.2.4"
|
||||
resolved "https://registry.npmjs.org/nock/-/nock-13.2.4.tgz#43a309d93143ee5cdcca91358614e7bde56d20e1"
|
||||
integrity sha512-8GPznwxcPNCH/h8B+XZcKjYPXnUV5clOKCjAqyjsiqA++MpNx9E9+t8YPp0MbThO+KauRo7aZJ1WuIZmOrT2Ug==
|
||||
dependencies:
|
||||
debug "^4.1.0"
|
||||
json-stringify-safe "^5.0.1"
|
||||
lodash.set "^4.3.2"
|
||||
propagate "^2.0.0"
|
||||
|
||||
node-abort-controller@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.0.1.tgz#f91fa50b1dee3f909afabb7e261b1e1d6b0cb74e"
|
||||
@@ -19759,6 +19774,11 @@ prop-types@^15.0.0, prop-types@^15.5.10, prop-types@^15.5.7, prop-types@^15.5.8,
|
||||
object-assign "^4.1.1"
|
||||
react-is "^16.13.1"
|
||||
|
||||
propagate@^2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45"
|
||||
integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==
|
||||
|
||||
properties-reader@^2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.npmjs.org/properties-reader/-/properties-reader-2.2.0.tgz#41d837fe143d8d5f2386b6a869a1975c0b2c595c"
|
||||
|
||||
Reference in New Issue
Block a user