Skip to content

Add msw with rates server snapshots #5611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@
"jest": "^29.6.3",
"jetifier": "^1.6.5",
"lint-staged": "^10.5.3",
"msw": "^2.8.4",
"msw-snapshot": "^5.3.0",
"node-fetch": "2.x",
"os-browserify": "^0.3.0",
"patch-package": "^6.2.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"request": {
"method": "POST",
"url": "https://rates1.edge.app/v2/exchangeRates",
"body": "{\"data\":[{\"currency_pair\":\"BTC_iso:USD\",\"date\":\"2022-06-01T04:00:00.000Z\"},{\"currency_pair\":\"ETH_iso:USD\",\"date\":\"2022-06-02T04:00:00.000Z\"},{\"currency_pair\":\"XMR_iso:EUR\",\"date\":\"2022-06-03T04:00:00.000Z\"},{\"currency_pair\":\"BTC_iso:PHP\",\"date\":\"2022-06-04T04:00:00.000Z\"},{\"currency_pair\":\"DOGE_iso:MXN\",\"date\":\"2022-06-04T04:00:00.000Z\"}]}",
"headers": [
[
"accept",
"*/*"
],
[
"accept-encoding",
"gzip,deflate"
],
[
"connection",
"close"
],
[
"content-length",
"341"
],
[
"content-type",
"application/json"
],
[
"host",
"rates1.edge.app"
],
[
"user-agent",
"node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
]
],
"cookies": []
},
"response": {
"status": 200,
"statusText": "OK",
"body": "{\"data\":[{\"currency_pair\":\"BTC_iso:USD\",\"date\":\"2022-06-01T04:00:00.000Z\",\"exchangeRate\":\"31616.87039234788244357333\"},{\"currency_pair\":\"ETH_iso:USD\",\"date\":\"2022-06-02T04:00:00.000Z\",\"exchangeRate\":\"1814.46024698976771105663\"},{\"currency_pair\":\"XMR_iso:EUR\",\"date\":\"2022-06-03T04:00:00.000Z\",\"exchangeRate\":\"184.82369193454304080736\"},{\"currency_pair\":\"BTC_iso:PHP\",\"date\":\"2022-06-04T04:00:00.000Z\",\"exchangeRate\":\"1553326.22872584574950798905\"},{\"currency_pair\":\"DOGE_iso:MXN\",\"date\":\"2022-06-04T04:00:00.000Z\",\"exchangeRate\":\"1.56164120620374275198\"}]}",
"headers": [
[
"access-control-allow-origin",
"*"
],
[
"alt-svc",
"h3=\":443\"; ma=2592000"
],
[
"connection",
"close"
],
[
"content-length",
"556"
],
[
"content-type",
"application/json; charset=utf-8"
],
[
"date",
"Tue, 03 Jun 2025 01:21:23 GMT"
],
[
"etag",
"W/\"22c-RGhPM+ynBEMz65VOLOSTYTu53U4\""
],
[
"server",
"Caddy, Caddy"
],
[
"vary",
"Accept-Encoding"
],
[
"x-powered-by",
"Express"
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"request": {
"method": "POST",
"url": "https://rates2.edge.app/v2/exchangeRates",
"body": "{\"data\":[{\"currency_pair\":\"BTC_iso:USD\",\"date\":\"2022-06-01T04:00:00.000Z\"},{\"currency_pair\":\"ETH_iso:USD\",\"date\":\"2022-06-02T04:00:00.000Z\"},{\"currency_pair\":\"XMR_iso:EUR\",\"date\":\"2022-06-03T04:00:00.000Z\"},{\"currency_pair\":\"BTC_iso:PHP\",\"date\":\"2022-06-04T04:00:00.000Z\"},{\"currency_pair\":\"DOGE_iso:MXN\",\"date\":\"2022-06-04T04:00:00.000Z\"}]}",
"headers": [
[
"accept",
"*/*"
],
[
"accept-encoding",
"gzip,deflate"
],
[
"connection",
"close"
],
[
"content-length",
"341"
],
[
"content-type",
"application/json"
],
[
"host",
"rates2.edge.app"
],
[
"user-agent",
"node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
]
],
"cookies": []
},
"response": {
"status": 200,
"statusText": "OK",
"body": "{\"data\":[{\"currency_pair\":\"BTC_iso:USD\",\"date\":\"2022-06-01T04:00:00.000Z\",\"exchangeRate\":\"31616.87039234788244357333\"},{\"currency_pair\":\"ETH_iso:USD\",\"date\":\"2022-06-02T04:00:00.000Z\",\"exchangeRate\":\"1814.46024698976771105663\"},{\"currency_pair\":\"XMR_iso:EUR\",\"date\":\"2022-06-03T04:00:00.000Z\",\"exchangeRate\":\"184.82369193454304080736\"},{\"currency_pair\":\"BTC_iso:PHP\",\"date\":\"2022-06-04T04:00:00.000Z\",\"exchangeRate\":\"1553326.22872584574950798905\"},{\"currency_pair\":\"DOGE_iso:MXN\",\"date\":\"2022-06-04T04:00:00.000Z\",\"exchangeRate\":\"1.56164120620374275198\"}]}",
"headers": [
[
"access-control-allow-origin",
"*"
],
[
"alt-svc",
"h3=\":443\"; ma=2592000"
],
[
"connection",
"close"
],
[
"content-length",
"556"
],
[
"content-type",
"application/json; charset=utf-8"
],
[
"date",
"Tue, 03 Jun 2025 01:10:43 GMT"
],
[
"etag",
"W/\"22c-RGhPM+ynBEMz65VOLOSTYTu53U4\""
],
[
"server",
"Caddy, Caddy"
],
[
"vary",
"Accept-Encoding"
],
[
"x-powered-by",
"Express"
]
]
}
}
5 changes: 5 additions & 0 deletions src/__tests__/exchangeRates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fetch from 'node-fetch'

import { closestRateForTimestamp, ExchangeRateCache } from '../actions/ExchangeRateActions'
import { getHistoricalRate } from '../util/exchangeRates'
import { mswServer } from '../util/mswServer'
import { snooze } from '../util/utils'

// Uncomment for testing under Node w/o Jest
Expand All @@ -13,6 +14,10 @@ import { snooze } from '../util/utils'

beforeAll(() => {
jest.useRealTimers()
mswServer.listen()
})
afterAll(() => {
mswServer.close()
})

const TEST_MAX_QUERY_SIZE = 2
Expand Down
9 changes: 9 additions & 0 deletions src/util/mswServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { setupServer } from 'msw/node'
import { snapshot } from 'msw-snapshot'

export const mswServer = setupServer(
snapshot({
basePath: './src/__mocks__/snapshots/',
updateSnapshots: 'missing'
})
)
Loading
Loading