-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add organizations api helper (#54)
<!--- Provide a general summary of your changes in the Title above --> ## Description Adds helper methods for making calls to the organizations api. Currently this only adds the get organizations by user id call. <!--- Describe your changes in detail --> <!--- Please include the phrase "BREAKING CHANGE:" here if your require a major release --> <!--- Don't forget to note any issues here with "fixes #<issue number>" --> ## How Has This Been Tested? Tests have been added to cover the new API call. <!--- Please describe in detail how you tested your changes. --> <!--- For bug fixes, include regression unit tests that fail without the fix --> <!--- For new features, include unit tests for the new functionality --> ## Screenshots (if appropriate): ## Checklist: <!--- Please mark an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> * [x] I have read the [**CONTRIBUTING** document](https://github.com/eventbrite/eventbrite-sdk-javascript/blob/master/CONTRIBUTING.md). * [x] I have updated the documentation accordingly. * [x] I have added tests to cover my changes. * [x] I have run `yarn validate` to ensure that tests, typescript and linting are all in order.
- Loading branch information
Showing
7 changed files
with
196 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
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,39 @@ | ||
# Organizations | ||
|
||
This is a collection of methods that are intended to be helpful wrappers around the [organizations API endpoints](organization-api-docs). | ||
|
||
View the [Organizations response object](organization-object-reference) for details on the properties you'll get back with each response. | ||
|
||
## Table on Contents | ||
|
||
- [`sdk.organizations.getByUser(id)`](#getByUser) | ||
|
||
<a id="getByUser"></a> | ||
|
||
## `sdk.organizations.getByUser(id)` | ||
Gets the details for a specific user by their user id. | ||
|
||
**Read [`/users/:userId/organizations/` documentation](organization-by-user) for more details.** | ||
|
||
### API | ||
```js | ||
sdk.organizations.getByUser(userId: string): Promise<Paginated<Organization[]>> | ||
``` | ||
|
||
### Example | ||
|
||
```js | ||
const eventbrite = require('eventbrite'); | ||
|
||
// Create configured Eventbrite SDK | ||
const sdk = eventbrite({token: 'OATH_TOKEN_HERE'}); | ||
|
||
sdk.organizations.getByUser('1234567890').then((paginatedResponse) => { | ||
console.log(`Here are your organizations: ${paginatedResponse.organizations.join(' ')}.`); | ||
}); | ||
``` | ||
|
||
<!-- link reference section --> | ||
[organization-api-docs]: https://www.eventbrite.com/platform/api#/reference/organization | ||
[organization-object-reference]: https://www.eventbrite.com/platform/api#/reference/organization | ||
[organization-by-user]: https://www.eventbrite.com/platform/api#/reference/organization/list-organizations-by-user |
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,67 @@ | ||
import { | ||
mockFetch, | ||
getMockFetch, | ||
getMockResponse, | ||
restoreMockFetch, | ||
} from './utils'; | ||
import { | ||
MOCK_ORGS_BY_USER_SUCCESS_RESPONSE, | ||
MOCK_TRANSFORMED_ORGS_BY_USER, | ||
} from './__fixtures__'; | ||
|
||
import request from '../request'; | ||
import {OrganizationsApi} from '../organizations'; | ||
|
||
describe('OrganizationsApi', () => { | ||
describe('getByUser()', () => { | ||
it('calls fetch and calls fetch with appropriate defaults', async() => { | ||
const organizations = new OrganizationsApi(request); | ||
|
||
mockFetch(getMockResponse(MOCK_ORGS_BY_USER_SUCCESS_RESPONSE)); | ||
|
||
await expect(organizations.getByUser('fake_id')).resolves.toEqual( | ||
MOCK_TRANSFORMED_ORGS_BY_USER | ||
); | ||
|
||
expect(getMockFetch()).toHaveBeenCalledTimes(1); | ||
expect(getMockFetch()).toHaveBeenCalledWith( | ||
'/users/fake_id/organizations/', | ||
expect.objectContaining({}) | ||
); | ||
|
||
restoreMockFetch(); | ||
}); | ||
|
||
it('handle token missing requests', async() => { | ||
const organizations = new OrganizationsApi(request); | ||
|
||
mockFetch( | ||
getMockResponse( | ||
{ | ||
status_code: 401, | ||
error_description: | ||
'An OAuth token is required for all requests', | ||
error: 'NO_AUTH', | ||
}, | ||
{status: 401} | ||
) | ||
); | ||
|
||
await expect( | ||
organizations.getByUser('fake_id') | ||
).rejects.toMatchObject({ | ||
response: expect.objectContaining({ | ||
status: 401, | ||
statusText: 'Unauthorized', | ||
ok: false, | ||
}), | ||
parsedError: { | ||
description: 'An OAuth token is required for all requests', | ||
error: 'NO_AUTH', | ||
}, | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {BaseApi} from './baseApi'; | ||
import {PaginatedResponse} from './types'; | ||
|
||
export interface Organization { | ||
id: string; | ||
name: string; | ||
imageId: string; | ||
locale?: string; | ||
vertical?: 'Default' | 'Music'; | ||
} | ||
|
||
/** | ||
* API for working with Organizations | ||
*/ | ||
export class OrganizationsApi extends BaseApi<PaginatedResponse<Organization>> { | ||
/** | ||
* Get organizations based off a user id. | ||
* @param {string} userId | ||
*/ | ||
getByUser(userId: string) { | ||
return this.request(`/users/${userId}/organizations/`); | ||
} | ||
} |
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