Skip to content

Commit

Permalink
fix: correct lowercase test
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jun 8, 2023
1 parent e189b72 commit 7e5ca7e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"auto-changelog": "^2.4.0",
"axios": "^1.3.1",
"axios": "^1.4.0",
"es-check": "^7.0.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions src/util/cache-predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export async function testCachePredicate<R = unknown, D = unknown>(
for (const [header, predicate] of Object.entries(containsHeaders)) {
if (
!(await predicate(
// Axios response headers are in lowercase, but check both just in case.

// FIXME: https://github.com/axios/axios/pull/5525
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
// Avoid bugs in case the header is not in lower case
response.headers[header.toLowerCase()] ?? response.headers[header]
))
) {
Expand Down
14 changes: 8 additions & 6 deletions test/util/cache-predicate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,25 @@ describe('tests cache predicate object', () => {
headers: { 'content-type': 'application/json' }
});

expect(await testCachePredicate(response, {})).toBeTruthy();

expect(
await testCachePredicate(response, {
containsHeaders: { 'content-type': () => true }
containsHeaders: { 'content-type': () => false }
})
).toBeTruthy();
).toBeFalsy();

expect(
await testCachePredicate(response, {
containsHeaders: { 'Content-Type': () => true }
containsHeaders: { 'Content-Type': () => false }
})
).toBeTruthy();
).toBeFalsy();

expect(
await testCachePredicate(response, {
containsHeaders: { 'Content-Type': () => true }
containsHeaders: { 'Content-Type': () => false }
})
).toBeTruthy();
).toBeFalsy();
});

it('tests containsHeader', async () => {
Expand Down

0 comments on commit 7e5ca7e

Please sign in to comment.