-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
313 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import test from 'ava' | ||
import td from 'testdouble' | ||
|
||
import * as transport from '../../src/transport' | ||
const requestStub = td.replace(transport, 'default') | ||
|
||
import rka from '../../src' | ||
|
||
test('memberships.ROLES', t => { | ||
const rokka = rka() | ||
t.deepEqual(rokka.memberships.ROLES, { READ: 'read', WRITE: 'write', ADMIN: 'admin' }) | ||
}) | ||
|
||
test('memberships.create', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
rokka.memberships.create('myorg', 'user@example.org', rokka.memberships.ROLES.ADMIN) | ||
|
||
const expectedArgs = { | ||
method: 'PUT', | ||
uri: 'https://api.rokka.io/organizations/myorg/memberships/user@example.org', | ||
body: { role: 'admin' }, | ||
qs: null | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) |
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,34 @@ | ||
import test from 'ava' | ||
import td from 'testdouble' | ||
|
||
import * as transport from '../../src/transport' | ||
const requestStub = td.replace(transport, 'default') | ||
|
||
import rka from '../../src' | ||
|
||
const knownOperations = ['resize', 'rotate', 'dropshadow', 'trim', 'crop', 'noop'] | ||
|
||
test('known operation functions exist', t => { | ||
t.plan(knownOperations.length) | ||
|
||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
knownOperations.forEach(key => { | ||
t.true(typeof rokka.operations[key] === 'function') | ||
}) | ||
}) | ||
|
||
test('operations.list', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
rokka.operations.list('myorg') | ||
|
||
const expectedArgs = { | ||
method: 'GET', | ||
uri: 'https://api.rokka.io/operations', | ||
body: null, | ||
qs: null | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) |
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,22 @@ | ||
import test from 'ava' | ||
import td from 'testdouble' | ||
|
||
import * as transport from '../../src/transport' | ||
const requestStub = td.replace(transport, 'default') | ||
|
||
import rka from '../../src' | ||
|
||
test('organizations.get', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
rokka.organizations.get('myorg') | ||
|
||
const expectedArgs = { | ||
method: 'GET', | ||
uri: 'https://api.rokka.io/organizations/myorg', | ||
body: null, | ||
qs: null | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) |
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,24 @@ | ||
import test from 'ava' | ||
|
||
import rka from '../../src' | ||
|
||
test('render.getUrl using stack', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
const url = rokka.render.getUrl('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a', 'png', 'mystack') | ||
|
||
t.is(url, 'https://myorg.rokka.io/mystack/c421f4e8cefe0fd3aab22832f51e85bacda0a47a.png') | ||
}) | ||
|
||
test('render.getUrl using custom operations', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
const operations = [ | ||
rokka.operations.rotate(45), | ||
rokka.operations.resize(100, 100) | ||
] | ||
|
||
const url = rokka.render.getUrl('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a', 'png', operations) | ||
|
||
t.not(url.indexOf('https://myorg.rokka.io/dynamic/rotate-angle-45--resize-width-100-height-100/c42'), -1) | ||
}) |
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,72 @@ | ||
import test from 'ava' | ||
import td from 'testdouble' | ||
|
||
import * as transport from '../../src/transport' | ||
const requestStub = td.replace(transport, 'default') | ||
|
||
import rka from '../../src' | ||
|
||
test('stacks.list', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
rokka.stacks.list('myorg') | ||
|
||
const expectedArgs = { | ||
method: 'GET', | ||
uri: 'https://api.rokka.io/stacks/myorg', | ||
body: null, | ||
qs: {} | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) | ||
|
||
test('stacks.get', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
rokka.stacks.get('myorg', 'mystack') | ||
|
||
const expectedArgs = { | ||
method: 'GET', | ||
uri: 'https://api.rokka.io/stacks/myorg/mystack', | ||
body: null, | ||
qs: null | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) | ||
|
||
test('stacks.create', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
const operations = [ | ||
rokka.operations.rotate(45), | ||
rokka.operations.resize(100, 100) | ||
] | ||
|
||
rokka.stacks.create('myorg', 'mystack', operations) | ||
|
||
const expectedArgs = { | ||
method: 'PUT', | ||
uri: 'https://api.rokka.io/stacks/myorg/mystack', | ||
body: operations, | ||
qs: null | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) | ||
|
||
test('stacks.delete', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
rokka.stacks.delete('myorg', 'mystack') | ||
|
||
const expectedArgs = { | ||
method: 'DELETE', | ||
uri: 'https://api.rokka.io/stacks/myorg/mystack', | ||
body: null, | ||
qs: null | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) |
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,22 @@ | ||
import test from 'ava' | ||
import td from 'testdouble' | ||
|
||
import * as transport from '../../src/transport' | ||
const requestStub = td.replace(transport, 'default') | ||
|
||
import rka from '../../src' | ||
|
||
test('stats.get', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
rokka.stats.get('myorg', '2017-01-01', '2017-01-31') | ||
|
||
const expectedArgs = { | ||
method: 'GET', | ||
uri: 'https://api.rokka.io/stats/myorg', | ||
qs: {from: '2017-01-01', to: '2017-01-31'}, | ||
body: null | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) |
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,21 @@ | ||
import test from 'ava' | ||
import td from 'testdouble' | ||
|
||
import * as transport from '../../src/transport' | ||
const requestStub = td.replace(transport, 'default') | ||
|
||
import rka from '../../src' | ||
|
||
test('users.create', t => { | ||
const rokka = rka({ apiKey: 'APIKEY' }) | ||
|
||
rokka.users.create('user@example.org') | ||
|
||
const expectedArgs = { | ||
method: 'POST', | ||
uri: 'https://api.rokka.io/users', | ||
body: { email: 'user@example.org' } | ||
} | ||
|
||
td.verify(requestStub(td.matchers.contains(expectedArgs), td.matchers.anything())) | ||
}) |
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,79 @@ | ||
import test from 'ava' | ||
import td from 'testdouble' | ||
|
||
import * as apis from '../src/apis' | ||
const apisStub = td.replace(apis, 'default') | ||
|
||
import * as transport from '../src/transport' | ||
const requestStub = td.replace(transport, 'default') | ||
|
||
import rokka from '../src' | ||
|
||
test('simple authorized request invocation', t => { | ||
rokka({ apiKey: 'APIKEY' }) | ||
const request = td.explain(apisStub).calls.slice(-1)[0].args[0].request | ||
|
||
request('get', 'test') | ||
}) | ||
|
||
test('simple non-authorized request invocation', t => { | ||
rokka() | ||
|
||
const request = td.explain(apisStub).calls.slice(-1)[0].args[0].request | ||
|
||
request('get', 'test', null, null, { noAuthHeaders: true }) | ||
}) | ||
|
||
test('missing API key', t => { | ||
rokka() | ||
|
||
const request = td.explain(apisStub).calls.slice(-1)[0].args[0].request | ||
|
||
t.throws(request('get', 'test'), 'Missing required property `apiKey`') | ||
}) | ||
|
||
test('request argument handling', t => { | ||
const apiHost = 'https://api.example.org' | ||
const apiVersion = 23 | ||
const apiKey = 'APIKEY' | ||
const path = 'test' | ||
const method = 'post' | ||
const body = { test: 'value' } | ||
const queryParams = { limit: 100, offset: 200 } | ||
|
||
const expectedArgs = { | ||
method, | ||
uri: `${apiHost}/${path}`, | ||
body, | ||
qs: queryParams, | ||
headers: { 'Api-Version': apiVersion, 'Api-Key': apiKey }, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
timeout: 30000 | ||
} | ||
|
||
rokka({ apiHost, apiKey, apiVersion }) | ||
|
||
const request = td.explain(apisStub).calls.slice(-1)[0].args[0].request | ||
|
||
request(method, path, body, queryParams) | ||
|
||
td.verify(requestStub(expectedArgs, td.matchers.isA(Object))) | ||
}) | ||
|
||
test('retry options handling', t => { | ||
const transportOptions = { | ||
retries: 23, | ||
minTimeout: 2323, | ||
maxTimeout: 232323, | ||
randomize: false | ||
} | ||
|
||
rokka({ apiKey: 'APIKEY', transport: transportOptions }) | ||
|
||
const request = td.explain(apisStub).calls.slice(-1)[0].args[0].request | ||
|
||
request('get', 'test') | ||
|
||
td.verify(requestStub(td.matchers.isA(Object), td.matchers.contains(transportOptions))) | ||
}) |