Skip to content

Instantly share code, notes, and snippets.

@Sivli-Embir
Last active September 28, 2021 17:17
Show Gist options
  • Save Sivli-Embir/2bddfe844552405b134def7b95d41370 to your computer and use it in GitHub Desktop.
Save Sivli-Embir/2bddfe844552405b134def7b95d41370 to your computer and use it in GitHub Desktop.
/**
* 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