-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(services/version): prevent checkForUpdate() 5xx response codes fr…
…om stopping connection
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { mock, test } from 'node:test' | ||
import * as assert from 'node:assert' | ||
import { checkForUpdate } from '../../src/services/version.js' | ||
import { STATUS_CODES } from 'node:http' | ||
|
||
test('checkForUpdate() handles 404 response', async (context) => { | ||
fetch = context.mock.fn(fetch, () => { | ||
return { | ||
status: 404 | ||
} | ||
}) | ||
|
||
const actual = await checkForUpdate() | ||
assert.deepEqual(actual, { available: false }) | ||
}) | ||
|
||
test('checkForUpdate() handles 5xx responses', async (context) => { | ||
const statusCodes = Object | ||
.keys(STATUS_CODES) | ||
.filter((statusCode) => +statusCode >= 500 ) | ||
.map((statusCode) => +statusCode) | ||
|
||
const statusContexts = statusCodes.map((statusCode) => { | ||
return { | ||
status: statusCode, | ||
expected: { available: false }, | ||
} | ||
}); | ||
|
||
for (const statusContext of statusContexts) { | ||
fetch = context.mock.fn(fetch, () => { | ||
return { | ||
status: statusContext.status, | ||
} | ||
}) | ||
|
||
const actual = await checkForUpdate() | ||
assert.deepEqual(actual, statusContext.expected) | ||
} | ||
}) |