mirror of https://github.com/ojizero/portal
10 changed files with 152 additions and 35 deletions
@ -1 +1,15 @@
@@ -1 +1,15 @@
|
||||
export default class Client {} |
||||
export interface Client { |
||||
request (method: string, path: string, options: any): void // TODO:
|
||||
} |
||||
|
||||
export class PortalClient implements Client { |
||||
constructor () { |
||||
// TODO:
|
||||
} |
||||
|
||||
request (method: string, path: string, options: any) { |
||||
// TODO:
|
||||
} |
||||
} |
||||
|
||||
export default PortalClient |
||||
|
@ -1 +1,41 @@
@@ -1 +1,41 @@
|
||||
export default class Method {} |
||||
import { Client } from './client' |
||||
|
||||
const applicationJson = 'application/json' |
||||
|
||||
export interface MethodSpec { |
||||
path: string, |
||||
method?: string, |
||||
body?: {}, |
||||
queryString?: {}, |
||||
contentType?: string, |
||||
accept?: string, |
||||
strict?: boolean, |
||||
} |
||||
|
||||
export function method (client: Client) { |
||||
return function methodGenerator (spec: MethodSpec) { |
||||
const { |
||||
path, |
||||
method = 'GET', |
||||
body = {}, |
||||
queryString = {}, |
||||
contentType = applicationJson, |
||||
accept = applicationJson, |
||||
strict = true |
||||
} = spec |
||||
|
||||
// It's ok for args here to be of implicit type any[]
|
||||
// @ts-ignore
|
||||
return function (...args) { |
||||
// TODO: replace path params with args
|
||||
// TODO: reject if args doesn't match path params if strict
|
||||
|
||||
// TODO: last argument is allowed to be object, JSON payload
|
||||
// TODO: reject if body doesn't match body spec if strict
|
||||
|
||||
return client.request(method, path, {}) |
||||
} |
||||
} |
||||
} |
||||
|
||||
export default method |
||||
|
@ -1,5 +1,9 @@
@@ -1,5 +1,9 @@
|
||||
import Client from '../src/client' |
||||
|
||||
describe('Client', () => { |
||||
// TODO:
|
||||
let client |
||||
|
||||
before(() => { |
||||
client = new Client() |
||||
}) |
||||
}) |
||||
|
@ -1,3 +1,59 @@
@@ -1,3 +1,59 @@
|
||||
/// <reference path='typings/globals.d.ts' />
|
||||
|
||||
import method from '../src/method' |
||||
|
||||
import { Client } from '../src/client' |
||||
import { MockClient } from './mocks/client' |
||||
|
||||
const mockMethodSpec = {} |
||||
|
||||
describe('Method', () => { |
||||
// TODO:
|
||||
let mockClient: Client |
||||
let methodGenerator |
||||
let methodFunction |
||||
|
||||
before(() => { |
||||
mockClient = new MockClient() |
||||
}) |
||||
|
||||
it('accepts client and returns generator function', () => { |
||||
methodGenerator = method(mockClient) |
||||
|
||||
expect(true).to.deep.equal(true) |
||||
// expect(methodFunction).to.be.a.function() // TODO:
|
||||
}) |
||||
|
||||
it('accepts a method specification and returns a method function', () =>{ |
||||
methodFunction = methodGenerator(mockMethodSpec) |
||||
|
||||
// expect(methodFunction).to.be.a.function() // TODO:
|
||||
}) |
||||
|
||||
describe('Method function', () => { |
||||
it('calls underlying request on client', () => { |
||||
methodFunction() |
||||
|
||||
// expect(someSpy).to.be.called.once.with.exaclty() // TODO:
|
||||
}) |
||||
|
||||
it('requires path parameters if specified', () => { |
||||
// methodFunction = undefined
|
||||
// methodFunction() // should throw
|
||||
}) |
||||
|
||||
it('passes path parameters if specified', () => { |
||||
// methodFunction = undefined
|
||||
// methodFunction(1) // should not throw
|
||||
}) |
||||
|
||||
it('requires body arguments if specified', () => { |
||||
// methodFunction = undefined
|
||||
// methodFunction() // should throw
|
||||
}) |
||||
|
||||
it('passes body arguments if specified', () => { |
||||
// methodFunction = undefined
|
||||
// methodFunction({ some: 'payload' })
|
||||
}) |
||||
}) |
||||
}) |
||||
|
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
import { Client } from '../../src/client' |
||||
|
||||
|
||||
export class MockClient implements Client { |
||||
constructor () { |
||||
//
|
||||
} |
||||
|
||||
request (method: string, options: any) { |
||||
//
|
||||
} |
||||
} |
||||
|
||||
// TODO: export spies as well
|
@ -1,23 +1,6 @@
@@ -1,23 +1,6 @@
|
||||
{ |
||||
"extends": "./tsconfig.json", |
||||
// "compilerOptions": { |
||||
// "sourceMap": false, |
||||
// "allowJs": false, |
||||
// "declaration": false, |
||||
// "rootDir": ".", |
||||
// "target": "ES6", |
||||
// "outDir": "./_tests", |
||||
// "moduleResolution": "node", |
||||
// "lib": [ |
||||
// "ES6", |
||||
// "ES2015", |
||||
// "ES2017.object" |
||||
// ] |
||||
// }, |
||||
"include": [ |
||||
"typings/*", |
||||
"test/typings/*", |
||||
"src/**/*", |
||||
"test/**/*" |
||||
] |
||||
"compilerOptions": { |
||||
"noImplicitAny": false |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue