Mocking config fs

This commit is contained in:
Ramon Gebben
2018-04-20 15:56:52 +02:00
parent 27b44a9367
commit 642fbd7fa2
2 changed files with 29 additions and 0 deletions

View File

@@ -6,6 +6,19 @@ const {
const mock = require('mock-fs');
describe('utils/doFetch', () => {
beforeEach(() => {
const configPath = `${__dirname}/../../../.config`;
const stub = {
userId: 42,
domain: 'gitlab.com',
privateToken: '90809657890'
};
mock({
[configPath]: JSON.stringify(stub)
});
});
test('it can fetch', async() => {
const mockResponse = [
{

View File

@@ -1,7 +1,21 @@
const fetch = require('node-fetch');
const { getMergeRequests } = require('./index');
const mock = require('mock-fs');
describe('utils/getMergeRequests', () => {
beforeEach(() => {
const configPath = `${__dirname}/../../../.config`;
const stub = {
userId: 42,
domain: 'gitlab.com',
privateToken: '90809657890'
};
mock({
[configPath]: JSON.stringify(stub)
});
});
it('should fetch merge requests', async() => {
const mockResponse = [
{
@@ -15,4 +29,6 @@ describe('utils/getMergeRequests', () => {
const mergeRequests = await getMergeRequests({});
expect(mergeRequests).toEqual(mockResponse);
});
afterEach(mock.restore);
});