-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(int-1031): Add customFetch method to Storyblok class
- Added unit tests to GET
- Loading branch information
Thiago Saife Rodrigues
committed
Dec 26, 2023
1 parent
a938d74
commit d2ef2c1
Showing
3 changed files
with
79 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
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,43 @@ | ||
import { expect, test, describe, beforeEach } from 'vitest' | ||
import StoryblokClient from 'src/index.ts' | ||
|
||
describe('customFetch', () => { | ||
let client | ||
|
||
beforeEach(() => { | ||
client = new StoryblokClient({ | ||
accessToken: process.env.VITE_ACCESS_TOKEN, | ||
oauthToken: process.env.VITE_OAUTH_TOKEN, | ||
}) | ||
}) | ||
|
||
test('should call GET method', async () => { | ||
const response = await client.customFetch( | ||
`spaces/${process.env.VITE_SPACE_ID}/stories`, | ||
{ | ||
method: 'GET', | ||
body: {}, | ||
} | ||
) | ||
expect(response).toHaveProperty('data') | ||
}) | ||
|
||
// Uncomment and adjust the following test if your API supports POST method for the endpoint | ||
// test('should call POST method', async () => { | ||
// const response = await client.customFetch(`spaces/${process.env.VITE_SPACE_ID}/stories`, { | ||
// method: 'POST', | ||
// body: JSON.stringify({ key: 'value' }), | ||
// }) | ||
// expect(response).toHaveProperty('data') | ||
// }) | ||
|
||
test('should return an error for invalid method', async () => { | ||
try { | ||
await client.customFetch(`spaces/${process.env.VITE_SPACE_ID}/stories`, { | ||
method: 'INVALID', | ||
}) | ||
} catch (error) { | ||
expect(error).toHaveProperty('message') | ||
} | ||
}) | ||
}) |