open-consul/ui-v2/tests/integration/services/repository/intention-test.js
John Cowen 746201ed49 ui: Adds XHR connection management to HTTP/1.1 installs (#5083)
Adds xhr connection managment to http/1.1 installs

This includes various things:

1. An object pool to 'acquire', 'release' and 'dispose' of objects, also
a 'purge' to completely empty it
2. A `Request` data object, mainly for reasoning about the object better
3. A pseudo http 'client' which doens't actually control the request
itself but does help to manage the connections

An initializer is used to detect the script element of the consul-ui sourcecode
which we use later to sniff the protocol that we are most likely using for API access
2019-05-01 18:22:02 +00:00

67 lines
1.8 KiB
JavaScript

import { moduleFor, test } from 'ember-qunit';
import repo from 'consul-ui/tests/helpers/repo';
const NAME = 'intention';
moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
integration: true,
});
const dc = 'dc-1';
const id = 'token-name';
test('findAllByDatacenter returns the correct data for list endpoint', function(assert) {
return repo(
'Intention',
'findAllByDatacenter',
this.subject(),
function retrieveStub(stub) {
return stub(`/v1/connect/intentions?dc=${dc}`, {
CONSUL_INTENTION_COUNT: '100',
});
},
function performTest(service) {
return service.findAllByDatacenter(dc);
},
function performAssertion(actual, expected) {
assert.deepEqual(
actual,
expected(function(payload) {
return payload.map(item =>
Object.assign({}, item, {
CreatedAt: new Date(item.CreatedAt),
UpdatedAt: new Date(item.UpdatedAt),
Datacenter: dc,
uid: `["${dc}","${item.ID}"]`,
})
);
})
);
}
);
});
test('findBySlug returns the correct data for item endpoint', function(assert) {
return repo(
'Intention',
'findBySlug',
this.subject(),
function(stub) {
return stub(`/v1/connect/intentions/${id}?dc=${dc}`);
},
function(service) {
return service.findBySlug(id, dc);
},
function(actual, expected) {
assert.deepEqual(
actual,
expected(function(payload) {
const item = payload;
return Object.assign({}, item, {
CreatedAt: new Date(item.CreatedAt),
UpdatedAt: new Date(item.UpdatedAt),
Datacenter: dc,
uid: `["${dc}","${item.ID}"]`,
});
})
);
}
);
});