2018-08-29 09:00:15 +00:00
|
|
|
import { moduleFor, test } from 'ember-qunit';
|
|
|
|
import repo from 'consul-ui/tests/helpers/repo';
|
2019-05-15 13:44:57 +00:00
|
|
|
import { get } from '@ember/object';
|
2018-08-29 09:00:15 +00:00
|
|
|
const NAME = 'session';
|
2018-10-26 16:36:15 +00:00
|
|
|
moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
|
2018-08-29 09:00:15 +00:00
|
|
|
// Specify the other units that are required for this test.
|
2018-10-26 16:36:15 +00:00
|
|
|
integration: true,
|
2018-08-29 09:00:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const dc = 'dc-1';
|
|
|
|
const id = 'node-name';
|
2019-05-15 13:44:57 +00:00
|
|
|
const now = new Date().getTime();
|
2019-12-17 18:47:37 +00:00
|
|
|
const undefinedNspace = 'default';
|
|
|
|
[undefinedNspace, 'team-1', undefined].forEach(nspace => {
|
|
|
|
test(`findByNode returns the correct data for list endpoint when the nspace is ${nspace}`, function(assert) {
|
|
|
|
get(this.subject(), 'store').serializerFor(NAME).timestamp = function() {
|
|
|
|
return now;
|
|
|
|
};
|
|
|
|
return repo(
|
|
|
|
'Session',
|
|
|
|
'findByNode',
|
|
|
|
this.subject(),
|
|
|
|
function retrieveStub(stub) {
|
|
|
|
return stub(
|
|
|
|
`/v1/session/node/${id}?dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}`,
|
|
|
|
{
|
|
|
|
CONSUL_SESSION_COUNT: '100',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function performTest(service) {
|
2021-02-23 08:56:42 +00:00
|
|
|
return service.findByNode({ id, dc, ns: nspace || undefinedNspace });
|
2019-12-17 18:47:37 +00:00
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
|
|
|
assert.deepEqual(
|
|
|
|
actual,
|
|
|
|
expected(function(payload) {
|
|
|
|
return payload.map(item =>
|
|
|
|
Object.assign({}, item, {
|
|
|
|
SyncTime: now,
|
|
|
|
Datacenter: dc,
|
|
|
|
Namespace: item.Namespace || undefinedNspace,
|
|
|
|
uid: `["${item.Namespace || undefinedNspace}","${dc}","${item.ID}"]`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
test(`findByKey returns the correct data for item endpoint when the nspace is ${nspace}`, function(assert) {
|
|
|
|
return repo(
|
|
|
|
'Session',
|
|
|
|
'findByKey',
|
|
|
|
this.subject(),
|
|
|
|
function(stub) {
|
|
|
|
return stub(
|
|
|
|
`/v1/session/info/${id}?dc=${dc}${typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``}`
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(service) {
|
2021-02-23 08:56:42 +00:00
|
|
|
return service.findByKey({ id, dc, ns: nspace || undefinedNspace });
|
2019-12-17 18:47:37 +00:00
|
|
|
},
|
|
|
|
function(actual, expected) {
|
|
|
|
assert.deepEqual(
|
|
|
|
actual,
|
|
|
|
expected(function(payload) {
|
|
|
|
const item = payload[0];
|
|
|
|
return Object.assign({}, item, {
|
2018-08-29 09:00:15 +00:00
|
|
|
Datacenter: dc,
|
2019-12-17 18:47:37 +00:00
|
|
|
Namespace: item.Namespace || undefinedNspace,
|
|
|
|
uid: `["${item.Namespace || undefinedNspace}","${dc}","${item.ID}"]`,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-08-29 09:00:15 +00:00
|
|
|
});
|