Skip to content

Commit

Permalink
Chore: Update mocks in tests for got changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Ross committed Jul 22, 2020
1 parent 5056510 commit 71836fc
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/download-data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const downloadsResponse: AIResponseQuery = JSON.parse(fs.readFileSync(path.join(
const downloadsEmptyResponse: AIResponseQuery = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', 'downloads-empty.json'), 'utf-8')); // eslint-disable-line no-sync

type Request = {
get: (url: string) => Promise<any>;
get: (url: string) => { json: () => Promise<any> };
}

type APIContext = {
Expand All @@ -22,7 +22,7 @@ type APIContext = {
const test = anyTest as TestInterface<APIContext>;

const loadScript = (context: APIContext) => {
return proxyquire('../../src/download-data/api', { got: context.request });
return proxyquire('../../src/download-data/api', { got: { default: context.request }});
};

test.beforeEach((t) => {
Expand All @@ -40,7 +40,11 @@ test.afterEach((t) => {
});

test(`'getFirefoxDownloadData' will request the data in just one query`, async (t) => {
const requestStub = sinon.stub(t.context.request, 'get').resolves({ body: firefoxDownloadsResponse });
const requestStub = sinon.stub(t.context.request, 'get').returns({
json: () => {
return Promise.resolve(firefoxDownloadsResponse);
}
});

const { getFirefoxDownloadData } = loadScript(t.context);

Expand All @@ -58,7 +62,11 @@ test(`'getFirefoxDownloadData' will request the data in just one query`, async (
});

test(`'getLatestDownloads' will return null if there is no data in App Insight`, async (t) => {
sinon.stub(t.context.request, 'get').resolves({ body: downloadsEmptyResponse });
sinon.stub(t.context.request, 'get').returns({
json: () => {
return Promise.resolve(downloadsEmptyResponse);
}
});

const { getLatestDownloads } = loadScript(t.context);

Expand All @@ -70,7 +78,11 @@ test(`'getLatestDownloads' will return null if there is no data in App Insight`,
});

test(`'getLatestDownloads' will request the data in just one query`, async (t) => {
const requestGetStub = sinon.stub(t.context.request, 'get').resolves({ body: downloadsResponse });
const requestGetStub = sinon.stub(t.context.request, 'get').returns({
json: () => {
return Promise.resolve(downloadsResponse);
}
});

const { getLatestDownloads } = loadScript(t.context);

Expand Down

0 comments on commit 71836fc

Please sign in to comment.