Skip to content

Commit

Permalink
Removes ill-thought out version option
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Nov 15, 2018
1 parent a95fdf1 commit d159644
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mockAxios from 'axios';
import Client from './client';

it('will be constructed using passed in options', async () => {
Client({ domain: 'admin', version: 'v2' });
Client('admin');

expect(mockAxios.create).toHaveBeenCalledWith({
baseURL: `https://admin.coconutcalendar.com/api/v2/open`,
Expand Down
6 changes: 2 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import axios, { AxiosInstance } from 'axios';

import { OpenApiOptions } from './types/options';

const Client = ({ domain, version }: OpenApiOptions): AxiosInstance => {
const Client = (domain: string): AxiosInstance => {
return axios.create({
baseURL: `https://${domain}.coconutcalendar.com/api/${version}/open`,
baseURL: `https://${domain}.coconutcalendar.com/api/v2/open`,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Expand Down
32 changes: 6 additions & 26 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,22 @@ import OpenApi from './index';
import Setting from './resources/setting';
import User from './resources/user';

it('will be constructed with appropriate required options', async () => {
const instance = new OpenApi({
domain: 'admin',
});
it('will be constructed properly', async () => {
const instance = new OpenApi('admin');

expect(instance).toHaveProperty('options', {
domain: 'admin',
version: 'v2',
});
});

it('will be constructed with all options', async () => {
const instance = new OpenApi({
domain: 'admin',
version: 'some-version',
});

expect(instance).toHaveProperty('options', {
domain: 'admin',
version: 'some-version',
});
expect(instance).toHaveProperty('client');
expect(instance).toHaveProperty('domain');
});

it('can access the user resource', async () => {
const instance = new OpenApi({
domain: 'admin',
});
const instance = new OpenApi('admin');

expect(instance).toHaveProperty('users');
expect(instance.users).toBeInstanceOf(User.prototype.constructor);
});

it('can access the setting resource', async () => {
const instance = new OpenApi({
domain: 'admin',
});
const instance = new OpenApi('admin');

expect(instance).toHaveProperty('settings');
expect(instance.settings).toBeInstanceOf(Setting.prototype.constructor);
Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import { AxiosInstance } from 'axios';
import Client from './client';
import Setting from './resources/setting';
import User from './resources/user';
import { OpenApiOptions } from './types/options';
import { Resource, UserResource } from './types/resources';

export default class OpenApi {
protected client: AxiosInstance;
protected options: OpenApiOptions;
protected domain: string;
protected setting: Resource;
protected user: UserResource;

constructor({ domain, version = 'v2' }: OpenApiOptions) {
this.client = Client({ domain, version });
this.options = { domain, version };
constructor(domain: string) {
this.client = Client(domain);
this.domain = domain;
this.setting = new Setting(this.client);
this.user = new User(this.client);
}
Expand Down
4 changes: 0 additions & 4 deletions src/types/options.d.ts

This file was deleted.

0 comments on commit d159644

Please sign in to comment.