forked from benmvp/eventbrite-sdk-javascript
-
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.
Added more test and methods to userMethods
- Loading branch information
Showing
3 changed files
with
107 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -129,5 +129,29 @@ describe('request', () => { | |
}) | ||
); | ||
}); | ||
|
||
it('combines request options properly', async() => { | ||
const {users} = eventbrite({ | ||
token: MOCK_TOKEN, | ||
baseUrl: MOCK_BASE_URL, | ||
}); | ||
const email = '[email protected]'; | ||
|
||
await expect(users.emailLookup(email)).resolves.toEqual( | ||
MOCK_TRANSFORMED_USERS_ME_RESPONSE_DATA | ||
); | ||
|
||
expect(getMockFetch()).toHaveBeenCalledTimes(1); | ||
expect(getMockFetch()).toHaveBeenCalledWith( | ||
`${MOCK_BASE_URL}/users/lookup/`, | ||
expect.objectContaining({ | ||
method: 'POST', | ||
body: JSON.stringify({email}), | ||
headers: expect.objectContaining({ | ||
Authorization: `Bearer ${MOCK_TOKEN}`, | ||
}), | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -59,3 +59,70 @@ describe('users.me()', () => { | |
restoreMockFetch(); | ||
}); | ||
}); | ||
|
||
describe('users.get(id)', () => { | ||
it('calls fetch and calls fetch with appropriate defaults', async() => { | ||
mockFetch(getMockResponse(MOCK_USERS_ME_RESPONSE_DATA)); | ||
|
||
await expect(users.get('142429416488')).resolves.toEqual( | ||
MOCK_TRANSFORMED_USERS_ME_RESPONSE_DATA | ||
); | ||
|
||
expect(getMockFetch()).toHaveBeenCalledTimes(1); | ||
expect(getMockFetch()).toHaveBeenCalledWith( | ||
'/users/142429416488/', | ||
expect.objectContaining({}) | ||
); | ||
|
||
restoreMockFetch(); | ||
}); | ||
|
||
it('should handle not found users', async() => { | ||
mockFetch( | ||
getMockResponse( | ||
{ | ||
status_code: 404, | ||
error_description: 'The user you requested does not exist.', | ||
error: 'NOT_FOUND', | ||
}, | ||
{status: 404} | ||
) | ||
); | ||
|
||
await expect(users.get('123')).rejects.toMatchObject({ | ||
response: expect.objectContaining({ | ||
status: 404, | ||
statusText: 'Not Found', | ||
ok: false, | ||
}), | ||
parsedError: { | ||
description: 'The user you requested does not exist.', | ||
error: 'NOT_FOUND', | ||
}, | ||
}); | ||
|
||
restoreMockFetch(); | ||
}); | ||
}); | ||
|
||
describe('users.emailLookup(email)', () => { | ||
it('calls fetch and calls fetch with appropriate defaults', async() => { | ||
mockFetch(getMockResponse(MOCK_USERS_ME_RESPONSE_DATA)); | ||
const email = '[email protected]'; | ||
|
||
await expect(users.emailLookup(email)).resolves.toEqual( | ||
MOCK_TRANSFORMED_USERS_ME_RESPONSE_DATA | ||
); | ||
|
||
expect(getMockFetch()).toHaveBeenCalledTimes(1); | ||
expect(getMockFetch()).toHaveBeenCalledWith( | ||
'/users/lookup/', | ||
expect.objectContaining({ | ||
method: 'POST', | ||
body: JSON.stringify({email}), | ||
}) | ||
); | ||
|
||
restoreMockFetch(); | ||
}); | ||
}); |
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