2022-09-01 15:37:37 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2018-08-29 09:00:15 +00:00
|
|
|
import repo from 'consul-ui/tests/helpers/repo';
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
module(`Integration | Service | session`, function (hooks) {
|
2022-09-01 15:37:37 +00:00
|
|
|
setupTest(hooks);
|
|
|
|
|
|
|
|
const dc = 'dc-1';
|
|
|
|
const id = 'node-name';
|
|
|
|
const now = new Date().getTime();
|
|
|
|
const undefinedNspace = 'default';
|
|
|
|
const undefinedPartition = 'default';
|
|
|
|
const partition = 'default';
|
2022-09-15 08:43:17 +00:00
|
|
|
[undefinedNspace, 'team-1', undefined].forEach((nspace) => {
|
|
|
|
test(`findByNode returns the correct data for list endpoint when the nspace is ${nspace}`, function (assert) {
|
2022-09-01 15:37:37 +00:00
|
|
|
const subject = this.owner.lookup('service:repository/session');
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
subject.store.serializerFor('session').timestamp = function () {
|
2022-09-01 15:37:37 +00:00
|
|
|
return now;
|
|
|
|
};
|
|
|
|
return repo(
|
|
|
|
'Session',
|
|
|
|
'findByNode',
|
|
|
|
subject,
|
|
|
|
function retrieveStub(stub) {
|
|
|
|
return stub(
|
|
|
|
`/v1/session/node/${id}?dc=${dc}${
|
|
|
|
typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``
|
|
|
|
}${typeof partition !== 'undefined' ? `&partition=${partition}` : ``}`,
|
|
|
|
{
|
|
|
|
CONSUL_SESSION_COUNT: '100',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function performTest(service) {
|
|
|
|
return service.findByNode({
|
|
|
|
id,
|
|
|
|
dc,
|
|
|
|
ns: nspace || undefinedNspace,
|
|
|
|
partition: partition || undefinedPartition,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function performAssertion(actual, expected) {
|
2022-09-15 08:43:17 +00:00
|
|
|
assert.propContains(
|
2022-09-01 15:37:37 +00:00
|
|
|
actual,
|
2022-09-15 08:43:17 +00:00
|
|
|
expected(function (payload) {
|
|
|
|
return payload.map((item) =>
|
2022-09-01 15:37:37 +00:00
|
|
|
Object.assign({}, item, {
|
|
|
|
SyncTime: now,
|
|
|
|
Datacenter: dc,
|
|
|
|
Namespace: item.Namespace || undefinedNspace,
|
|
|
|
Partition: item.Partition || undefinedPartition,
|
2022-09-15 08:43:17 +00:00
|
|
|
uid: `["${item.Partition || undefinedPartition}","${
|
|
|
|
item.Namespace || undefinedNspace
|
|
|
|
}","${dc}","${item.ID}"]`,
|
2022-09-01 15:37:37 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
test(`findByKey returns the correct data for item endpoint when the nspace is ${nspace}`, function (assert) {
|
2022-09-01 15:37:37 +00:00
|
|
|
const subject = this.owner.lookup('service:repository/session');
|
|
|
|
return repo(
|
|
|
|
'Session',
|
|
|
|
'findByKey',
|
|
|
|
subject,
|
2022-09-15 08:43:17 +00:00
|
|
|
function (stub) {
|
2022-09-01 15:37:37 +00:00
|
|
|
return stub(
|
|
|
|
`/v1/session/info/${id}?dc=${dc}${
|
|
|
|
typeof nspace !== 'undefined' ? `&ns=${nspace}` : ``
|
|
|
|
}${typeof partition !== 'undefined' ? `&partition=${partition}` : ``}`
|
|
|
|
);
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
function (service) {
|
2022-09-01 15:37:37 +00:00
|
|
|
return service.findByKey({
|
|
|
|
id,
|
|
|
|
dc,
|
|
|
|
ns: nspace || undefinedNspace,
|
|
|
|
partition: partition || undefinedPartition,
|
|
|
|
});
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
function (actual, expected) {
|
|
|
|
assert.propContains(
|
2022-09-01 15:37:37 +00:00
|
|
|
actual,
|
2022-09-15 08:43:17 +00:00
|
|
|
expected(function (payload) {
|
2022-09-01 15:37:37 +00:00
|
|
|
const item = payload[0];
|
|
|
|
return Object.assign({}, item, {
|
2019-12-17 18:47:37 +00:00
|
|
|
Datacenter: dc,
|
|
|
|
Namespace: item.Namespace || undefinedNspace,
|
2021-09-15 18:50:11 +00:00
|
|
|
Partition: item.Partition || undefinedPartition,
|
2022-09-15 08:43:17 +00:00
|
|
|
uid: `["${item.Partition || undefinedPartition}","${
|
|
|
|
item.Namespace || undefinedNspace
|
|
|
|
}","${dc}","${item.ID}"]`,
|
2022-09-01 15:37:37 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2019-12-17 18:47:37 +00:00
|
|
|
});
|
2018-08-29 09:00:15 +00:00
|
|
|
});
|