Files
threshold-ui/addons/api/tests/unit/models/worker-test.js
T
hashicorp-copywrite[bot]andCameron Perera 3d610427d0 [COMPLIANCE] Add Copyright and License Headers (#1617)
* [COMPLIANCE] Add Copyright and License Headers

* chore: 🤖 update Copyright headers to satisfy our lint rules

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2023-03-01 09:39:41 -06:00

41 lines
1.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
module('Unit | Model | worker', function (hooks) {
setupTest(hooks);
setupMirage(hooks);
test('it has a `createWorkerLed` method that targets a specific POST API', async function (assert) {
assert.expect(2);
const scopeId = 'global';
const workerGeneratedAuthToken = 'token';
this.server.post('/v1/workers:create:worker-led', (schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
scope_id: scopeId,
worker_generated_auth_token: workerGeneratedAuthToken,
});
return { id: '123abc' };
});
const store = this.owner.lookup('service:store');
const model = store.createRecord('worker', {
type: 'pki',
scope: {
scope_id: scopeId,
type: 'global',
},
});
await model.createWorkerLed(workerGeneratedAuthToken);
const worker = store.peekRecord('worker', '123abc');
assert.ok(worker);
});
});