open-consul/ui-v2/tests/integration/adapters/session/response-test.js
John Cowen 7903512b26
UI - Refactor Adapter.handleResponse (#4398)
* Add some tests to check the correct GET API endpoints are called

* Refactor adapters

1. Add integration tests for `urlFor...` and majority `handleResponse` methods
2. Refactor out `handleResponse` a little more into single/batch/boolean
methods
3. Move setting of the `Datacenter` property into the `handleResponse`
method, basically the same place that the uid is being set using the dc
parsed form the URL
4. Add some Errors for if you don't pass ids to certain `urlFor` methods
2018-07-30 17:55:44 +01:00

40 lines
1.4 KiB
JavaScript

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { get } from 'consul-ui/tests/helpers/api';
module('Integration | Adapter | session | response', function(hooks) {
setupTest(hooks);
const dc = 'dc-1';
const id = 'session-id';
test('handleResponse returns the correct data for list endpoint', function(assert) {
const adapter = this.owner.lookup('adapter:session');
const node = 'node-id';
const request = {
url: `/v1/session/node/${node}?dc=${dc}`,
};
return get(request.url).then(function(payload) {
const expected = payload.map(item =>
Object.assign({}, item, {
Datacenter: dc,
uid: `["${dc}","${item.ID}"]`,
})
);
const actual = adapter.handleResponse(200, {}, payload, request);
assert.deepEqual(actual, expected);
});
});
test('handleResponse returns the correct data for item endpoint', function(assert) {
const adapter = this.owner.lookup('adapter:session');
const request = {
url: `/v1/session/info/${id}?dc=${dc}`,
};
return get(request.url).then(function(payload) {
const expected = Object.assign({}, payload[0], {
Datacenter: dc,
uid: `["${dc}","${id}"]`,
});
const actual = adapter.handleResponse(200, {}, payload, request);
assert.deepEqual(actual, expected);
});
});
});