-
Notifications
You must be signed in to change notification settings - Fork 36
/
test-setup.js
34 lines (30 loc) · 1.07 KB
/
test-setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const _ = require('lodash');
const request = require('requestretry');
const sdk = require('./lib/logic/sdk');
const { Config } = require('codefresh-sdk');
const openapi = require('./openapi');
jest.mock('./lib/output/Output');
jest.mock('codefresh-sdk/helpers/whoami', () => ({
getUser: jest.fn().mockResolvedValue(),
getExecutionContext: jest.fn().mockResolvedValue(),
getCurrentAccount: jest.fn().mockResolvedValue(),
}));
jest.mock('request-promise', () => (() => ({ options: { request: {} } })));
let SDK_CONFIGURED;
global.verifyResponsesReturned = async (responses) => {
const { results } = request.mock;
let returnedResponses = _.map(results, r => r.value);
returnedResponses = await Promise.all(returnedResponses);
expect(returnedResponses).toEqual(responses);
};
/**
* downloads spec one time for all tests
* */
global.configureSdk = async () => {
Object.keys(sdk).forEach(key => delete sdk[key]);
sdk.configure(await Config.load({
url: 'http://not.needed',
apiKey: 'not-needed',
spec: { json: openapi },
}));
};