-
-
Save Sivli-Embir/2bddfe844552405b134def7b95d41370 to your computer and use it in GitHub Desktop.
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
/** | |
* Assume this is syntactically the same as the fetch API with the application/json header | |
* This mock fetch call has three outputs: | |
* | |
* If no cursor is given it returns a response with data: ['a', 'b', 'c'] | |
* and a cursor string of VALID_CURSOR. | |
* If it is given the VALID_CURSOR it returns data: [ 'd', 'e' ]. | |
* If its given an invalid cursor it will return an error property. | |
**/ | |
export const VALID_CURSOR = "asdfghjkl" | |
const mockJson = async (data) => data | |
const mockFetchEndpoint = async (cursor) => { | |
if (!cursor) { | |
return { | |
status: 200, | |
ok: true, | |
json: mockJson({ | |
cursor: VALID_CURSOR, | |
data: ["a","b","c"] | |
}) | |
} | |
} | |
if (cursor == VALID_CURSOR) { | |
return { | |
status: 200, | |
ok: true, | |
json: mockJson({ | |
cursor: null, | |
data: [ 'd', 'e' ] | |
}) | |
} | |
} | |
return { | |
status: 418, | |
ok: false, | |
json: mockJson({ | |
error: "invalid data" | |
}) | |
} | |
} | |
export default mockFetchEndpoint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment