2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
module('Integration | Adapter | partition', function (hooks) {
|
2021-09-15 18:50:11 +00:00
|
|
|
setupTest(hooks);
|
|
|
|
const dc = 'dc-1';
|
|
|
|
const id = 'slug';
|
2022-09-15 08:43:17 +00:00
|
|
|
test('requestForQuery returns the correct url/method', async function (assert) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const adapter = this.owner.lookup('adapter:partition');
|
|
|
|
const client = this.owner.lookup('service:client/http');
|
2022-09-15 08:43:17 +00:00
|
|
|
const request = function () {
|
2021-09-15 18:50:11 +00:00
|
|
|
return () => client.requestParams.bind(client)(...arguments);
|
|
|
|
};
|
|
|
|
const expected = `GET /v1/partitions?dc=${dc}`;
|
|
|
|
let actual = await adapter.requestForQuery(request, {
|
|
|
|
dc: dc,
|
|
|
|
});
|
|
|
|
actual = actual();
|
|
|
|
assert.equal(`${actual.method} ${actual.url}`, expected);
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
test('requestForQueryRecord returns the correct url/method', async function (assert) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const adapter = this.owner.lookup('adapter:partition');
|
|
|
|
const client = this.owner.lookup('service:client/http');
|
2022-09-15 08:43:17 +00:00
|
|
|
const request = function () {
|
2021-09-15 18:50:11 +00:00
|
|
|
return () => client.requestParams.bind(client)(...arguments);
|
|
|
|
};
|
|
|
|
const expected = `GET /v1/partition/${id}?dc=${dc}`;
|
|
|
|
let actual = await adapter.requestForQueryRecord(request, {
|
|
|
|
dc: dc,
|
|
|
|
id: id,
|
|
|
|
});
|
|
|
|
actual = actual();
|
|
|
|
assert.equal(`${actual.method} ${actual.url}`, expected);
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
test("requestForQueryRecord throws if you don't specify an id", function (assert) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const adapter = this.owner.lookup('adapter:partition');
|
|
|
|
const client = this.owner.lookup('service:client/http');
|
2022-09-15 08:43:17 +00:00
|
|
|
const request = function () {
|
2021-09-15 18:50:11 +00:00
|
|
|
return () => client.requestParams.bind(client)(...arguments);
|
|
|
|
};
|
|
|
|
assert.rejects(
|
|
|
|
adapter.requestForQueryRecord(request, {
|
|
|
|
dc: dc,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|