-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Inject cozy-client - stage 11 - cozyFetchJSON
simple wrapper around internal `fetchJSON()` maintaining compatibility with the old cozy-client-js
- Loading branch information
Showing
2 changed files
with
75 additions
and
2 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
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,49 @@ | ||
import stack from 'lib/stack-client' | ||
|
||
describe("stack client", () => { | ||
|
||
describe("cozyFetchJSON", () => { | ||
|
||
let json = jest.fn().mockReturnValue({ | ||
data: { id: "myid" } | ||
}) | ||
let fetch = jest.fn().mockResolvedValue({ | ||
status:200, | ||
headers: { | ||
get: (header) => 'application/json' | ||
}, | ||
json | ||
}) | ||
let cozyClient = { | ||
getStackClient: () => { | ||
return { | ||
token: { token: "mytoken"}, | ||
uri: "https://test.mycozy.cloud", | ||
fetch | ||
} | ||
} | ||
} | ||
let params = { | ||
cozyClient, | ||
onCreateApp: function() {}, | ||
onDeleteApp: function() {}, | ||
} | ||
|
||
beforeAll(async () => { | ||
await stack.init(params) | ||
}) | ||
|
||
it("should transform `id` in `_id`", async () => { | ||
const data = await stack.cozyFetchJSON('_', 'GET', '/path') | ||
expect( data._id ).toBe('myid') | ||
}) | ||
|
||
it("should call fetch from cozy-client", async () => { | ||
fetch.mockClear() | ||
const data = await stack.cozyFetchJSON('_', 'GET', '/path') | ||
expect( fetch ).toHaveBeenCalled() | ||
}) | ||
|
||
}) | ||
|
||
}) |