forked from wger-project/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow fetching more measurements than the first page only
When all measurements of a specific category where fetched, it would only receive the first 20 even tough there were more. This is now fixed by fetching all pages. See: wger-project#782
- Loading branch information
Showing
2 changed files
with
69 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import axios from "axios"; | ||
import { MeasurementCategory } from "components/Measurements/models/Category"; | ||
import { MeasurementEntry } from "components/Measurements/models/Entry"; | ||
import { getMeasurementCategories } from "services/measurements"; | ||
|
||
jest.mock("axios"); | ||
|
||
describe('measurement service tests', () => { | ||
test('GET measurement categories', async () => { | ||
const measurementResponse = { | ||
count: 2, | ||
next: null, | ||
previous: null, | ||
results: [ | ||
{ | ||
"id": 1, | ||
"name": "Weight", | ||
"unit": "kg" | ||
} | ||
] | ||
}; | ||
|
||
const measurementEntryResponse = { | ||
count: 2, | ||
next: null, | ||
previous: null, | ||
results: [ | ||
{ | ||
"id": 1, | ||
"category": 1, | ||
"value": 80, | ||
"date": "2021-01-01", | ||
"notes": "" | ||
} | ||
] | ||
}; | ||
|
||
// @ts-ignore | ||
axios.get.mockImplementation((url: string) => { | ||
if (url.includes("measurement-category")) { | ||
return Promise.resolve({ data: measurementResponse }); | ||
} else if (url.includes("measurement/?category=1")) { | ||
return Promise.resolve({ data: measurementEntryResponse }); | ||
} | ||
}); | ||
|
||
const result = await getMeasurementCategories(); | ||
expect(axios.get).toHaveBeenCalledTimes(2); | ||
|
||
expect(result).toStrictEqual([ | ||
new MeasurementCategory(1, "Weight", "kg", [ | ||
new MeasurementEntry(1, 1, new Date("2021-01-01"), 80, "") | ||
]) | ||
]); | ||
}); | ||
}); |
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