Skip to content

Commit

Permalink
patch(organizations) Update SDK to expose organization helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
kwelch-eb authored Jan 30, 2019
1 parent d99fd28 commit c661106
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import {
MOCK_USERS_ME_RESPONSE_DATA,
MOCK_TRANSFORMED_USERS_ME_RESPONSE_DATA,
MOCK_TRANSFORMED_ORGS_BY_USER,
MOCK_ORGS_BY_USER_SUCCESS_RESPONSE,
} from './__fixtures__';

describe('configurations', () => {
Expand Down Expand Up @@ -130,4 +132,45 @@ describe('request', () => {
);
});
});

describe('organizations collection', () => {
it('should return an object of functions', () => {
mockFetch(getMockResponse(MOCK_ORGS_BY_USER_SUCCESS_RESPONSE));

const {organizations} = eventbrite({
token: MOCK_TOKEN,
baseUrl: MOCK_BASE_URL,
});

expect(organizations).toBeDefined();
Object.keys(organizations).forEach((key) => {
const value = (organizations as any)[key];

expect(value).toBeInstanceOf(Function);
});
});

it('makes request to API base url override w/ specified token', async() => {
mockFetch(getMockResponse(MOCK_ORGS_BY_USER_SUCCESS_RESPONSE));

const {organizations} = eventbrite({
token: MOCK_TOKEN,
baseUrl: MOCK_BASE_URL,
});

await expect(organizations.getByUser('fake_id')).resolves.toEqual(
MOCK_TRANSFORMED_ORGS_BY_USER
);

expect(getMockFetch()).toHaveBeenCalledTimes(1);
expect(getMockFetch()).toHaveBeenCalledWith(
`${MOCK_BASE_URL}/users/fake_id/organizations/`,
expect.objectContaining({
headers: expect.objectContaining({
Authorization: `Bearer ${MOCK_TOKEN}`,
}),
})
);
});
});
});
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Sdk, SdkConfig, JSONRequest} from './types';
import request from './request';
import {UserApi} from './users';
import {OrganizationsApi} from './organizations';

export * from './constants';

Expand Down Expand Up @@ -37,6 +38,7 @@ const eventbrite = ({
return {
request: jsonRequest,
users: new UserApi(jsonRequest),
organizations: new OrganizationsApi(jsonRequest),
};
};

Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {UserApi} from './users';
import {OrganizationsApi} from './organizations';

export interface SdkConfig {
token?: string;
Expand All @@ -13,6 +14,7 @@ export type JSONRequest<T = {}> = (
export interface Sdk {
request: JSONRequest;
users: UserApi;
organizations: OrganizationsApi;
}

export interface ArgumentErrors {
Expand Down Expand Up @@ -42,6 +44,6 @@ export interface Pagination {
}

export interface PaginatedResponse<T> {
pagination: Pagination;
pagination?: Pagination;
[key: string]: T[] | Pagination;
}

0 comments on commit c661106

Please sign in to comment.