1 | var assert = require('assert');
|
2 | var MockHttpClient = require('./mock-http-client');
|
3 | var MemoryStore = require('ac-node').MemoryStore;
|
4 | var RestClient = require('..').RestClient;
|
5 |
|
6 | describe('ac hipchat rest client', function () {
|
7 |
|
8 | var store = MemoryStore();
|
9 | var httpClient = MockHttpClient(10);
|
10 |
|
11 | afterEach(function *() {
|
12 | yield store.clear();
|
13 | });
|
14 |
|
15 | describe('stateless rest client', function () {
|
16 |
|
17 | var restClient = RestClient(httpClient);
|
18 |
|
19 | it('should fetch capabilities', function *() {
|
20 | var capabilitiesUrl = 'https://mock.hipchat.com/v2/capabilities';
|
21 | var capabilities = yield restClient.getCapabilities(capabilitiesUrl);
|
22 | assert.equal(capabilities.links.self, capabilitiesUrl);
|
23 | });
|
24 |
|
25 | it('should fetch an oauth token', function *() {
|
26 | var tokenUrl = 'https://mock.hipchat.com/v2/oauth/token';
|
27 | var username = 'foo';
|
28 | var password = 'bar';
|
29 | var scopes = [];
|
30 | var tokenData = yield restClient.generateToken(tokenUrl, username, password, scopes);
|
31 | assert.equal(tokenData.access_token, '1a2b3c4d5e6f');
|
32 | });
|
33 |
|
34 | });
|
35 |
|
36 | });
|