From c6611067548bfcd04a2f88031192a00d9034c9a9 Mon Sep 17 00:00:00 2001 From: Kyle Welch <33464278+kwelch-eb@users.noreply.github.com> Date: Wed, 30 Jan 2019 12:49:58 -0600 Subject: [PATCH] patch(organizations) Update SDK to expose organization helpers --- src/__tests__/index.spec.ts | 43 +++++++++++++++++++++++++++++++++++++ src/index.ts | 2 ++ src/types.ts | 4 +++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/__tests__/index.spec.ts b/src/__tests__/index.spec.ts index ddb799f..cddf4ee 100644 --- a/src/__tests__/index.spec.ts +++ b/src/__tests__/index.spec.ts @@ -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', () => { @@ -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}`, + }), + }) + ); + }); + }); }); diff --git a/src/index.ts b/src/index.ts index 2ae9ac3..7f14b62 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -37,6 +38,7 @@ const eventbrite = ({ return { request: jsonRequest, users: new UserApi(jsonRequest), + organizations: new OrganizationsApi(jsonRequest), }; }; diff --git a/src/types.ts b/src/types.ts index f5c0920..f464df8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import {UserApi} from './users'; +import {OrganizationsApi} from './organizations'; export interface SdkConfig { token?: string; @@ -13,6 +14,7 @@ export type JSONRequest = ( export interface Sdk { request: JSONRequest; users: UserApi; + organizations: OrganizationsApi; } export interface ArgumentErrors { @@ -42,6 +44,6 @@ export interface Pagination { } export interface PaginatedResponse { - pagination: Pagination; + pagination?: Pagination; [key: string]: T[] | Pagination; }