2018-08-29 09:00:15 +00:00
|
|
|
import { moduleFor, test } from 'ember-qunit';
|
|
|
|
import repo from 'consul-ui/tests/helpers/repo';
|
2020-04-24 13:37:35 +00:00
|
|
|
import { get } from '@ember/object';
|
2018-08-29 09:00:15 +00:00
|
|
|
const NAME = 'intention';
|
2018-10-26 16:36:15 +00:00
|
|
|
moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
|
2019-01-25 12:30:51 +00:00
|
|
|
integration: true,
|
2018-08-29 09:00:15 +00:00
|
|
|
});
|
|
|
|
|
2020-04-24 13:37:35 +00:00
|
|
|
const now = new Date().getTime();
|
2018-08-29 09:00:15 +00:00
|
|
|
const dc = 'dc-1';
|
|
|
|
const id = 'token-name';
|
2019-12-17 18:47:37 +00:00
|
|
|
const nspace = 'default';
|
2018-08-29 09:00:15 +00:00
|
|
|
test('findAllByDatacenter returns the correct data for list endpoint', function(assert) {
|
2020-04-24 13:37:35 +00:00
|
|
|
get(this.subject(), 'store').serializerFor(NAME).timestamp = function() {
|
|
|
|
return now;
|
|
|
|
};
|
2018-08-29 09:00:15 +00:00
|
|
|
return repo(
|
|
|
|
'Intention',
|
|
|
|
'findAllByDatacenter',
|
|
|
|
this.subject(),
|
|
|
|
function retrieveStub(stub) {
|
|
|
|
return stub(`/v1/connect/intentions?dc=${dc}`, {
|
2020-09-18 10:14:06 +00:00
|
|
|
CONSUL_INTENTION_COUNT: '1',
|
2018-08-29 09:00:15 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
function performTest(service) {
|
|
|
|
return service.findAllByDatacenter(dc);
|
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
|
|
|
assert.deepEqual(
|
2020-09-18 10:14:06 +00:00
|
|
|
actual[0],
|
2018-08-29 09:00:15 +00:00
|
|
|
expected(function(payload) {
|
2020-09-18 10:14:06 +00:00
|
|
|
const item = payload[0];
|
|
|
|
return {
|
|
|
|
...item,
|
|
|
|
CreatedAt: new Date(item.CreatedAt),
|
|
|
|
UpdatedAt: new Date(item.UpdatedAt),
|
|
|
|
Legacy: true,
|
|
|
|
SyncTime: now,
|
|
|
|
Datacenter: dc,
|
|
|
|
// TODO: nspace isn't required here, once we've
|
|
|
|
// refactored out our Serializer this can go
|
|
|
|
uid: `["${nspace}","${dc}","${item.ID}"]`,
|
|
|
|
};
|
2018-08-29 09:00:15 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
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, {
|
2020-09-18 10:14:06 +00:00
|
|
|
Legacy: true,
|
2018-08-29 09:00:15 +00:00
|
|
|
CreatedAt: new Date(item.CreatedAt),
|
|
|
|
UpdatedAt: new Date(item.UpdatedAt),
|
|
|
|
Datacenter: dc,
|
2019-12-17 18:47:37 +00:00
|
|
|
// TODO: nspace isn't required here, once we've
|
|
|
|
// refactored out our Serializer this can go
|
|
|
|
uid: `["${nspace}","${dc}","${item.ID}"]`,
|
2018-08-29 09:00:15 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|