Skip to content

Commit

Permalink
move tests around for diff cleanliness
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Dec 9, 2022
1 parent 452395b commit 52a1ee5
Showing 1 changed file with 62 additions and 50 deletions.
112 changes: 62 additions & 50 deletions src/__tests__/RESTDataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ describe('RESTDataSource', () => {
deleteFoo() {
return this.delete('foo');
}

headFoo() {
return this.head('foo');
}
})();

const expectedFoo = { foo: 'bar' };
Expand Down Expand Up @@ -475,6 +479,64 @@ describe('RESTDataSource', () => {

expect(data).toEqual(expectedFoo);
});

it('HEAD', async () => {
nock(apiUrl).head('/foo').reply(200);

const response = await dataSource.headFoo();

expect(response.status).toEqual(200);
});
});

describe('HEAD requests', () => {
it('Deduplicates HEAD requests', async () => {
const dataSource = new (class extends RESTDataSource {
override baseURL = apiUrl;

headFoo(id: number) {
return this.head(`foo/${id}`);
}
})();

nock(apiUrl).head('/foo/1').reply(200);

await Promise.all([dataSource.headFoo(1), dataSource.headFoo(1)]);
});

it('Does not cache HEAD results', async () => {
const dataSource = new (class extends RESTDataSource {
override baseURL = apiUrl;

headFoo(id: number) {
return this.head(`foo/${id}`);
}
})();

nock(apiUrl).head('/foo/1').reply(200);
nock(apiUrl).head('/foo/1').reply(200);

await dataSource.headFoo(1);
await dataSource.headFoo(1);
});

it('Does not cache HEAD results even when TTL override is provided', async () => {
const dataSource = new (class extends RESTDataSource {
override baseURL = apiUrl;

headFoo(id: number) {
return this.head(`foo/${id}`, {
cacheOptions: { ttl: 3000 },
});
}
})();

nock(apiUrl).head('/foo/1').reply(200);
nock(apiUrl).head('/foo/1').reply(200);

await dataSource.headFoo(1);
await dataSource.headFoo(1);
});
});

describe('response parsing', () => {
Expand Down Expand Up @@ -1145,56 +1207,6 @@ describe('RESTDataSource', () => {
await dataSource.getFoo(2, true);
});

describe('HEAD requests', () => {
it('Deduplicates HEAD requests', async () => {
const dataSource = new (class extends RESTDataSource {
override baseURL = apiUrl;

headFoo(id: number) {
return this.head(`foo/${id}`);
}
})();

nock(apiUrl).head('/foo/1').reply(200);

await Promise.all([dataSource.headFoo(1), dataSource.headFoo(1)]);
});

it('Does not cache HEAD results', async () => {
const dataSource = new (class extends RESTDataSource {
override baseURL = apiUrl;

headFoo(id: number) {
return this.head(`foo/${id}`);
}
})();

nock(apiUrl).head('/foo/1').reply(200);
nock(apiUrl).head('/foo/1').reply(200);

await dataSource.headFoo(1);
await dataSource.headFoo(1);
});

it('Does not cache HEAD results even when TTL override is provided', async () => {
const dataSource = new (class extends RESTDataSource {
override baseURL = apiUrl;

headFoo(id: number) {
return this.head(`foo/${id}`, {
cacheOptions: { ttl: 3000 },
});
}
})();

nock(apiUrl).head('/foo/1').reply(200);
nock(apiUrl).head('/foo/1').reply(200);

await dataSource.headFoo(1);
await dataSource.headFoo(1);
});
});

describe('user hooks', () => {
describe('willSendRequest', () => {
const obj = { foo: 'bar' };
Expand Down

0 comments on commit 52a1ee5

Please sign in to comment.