Files
threshold-ui/addons/api/tests/unit/serializers/worker-test.js
T
Devon AndersonandDharini Jeeva 62077d3c25 feat: 🎸 Add worker serializer (#1230)
* feat: 🎸 Add worker serializer

Add worker serializer that focus' on `config_tags.type` and
`canonical_tags.type`.
[API](https://docs.google.com/document/d/1G-lfl8gk9NfoKFImSpHb90E3xC3CSEVDwVy3bJ9eOhA/edit#heading=h.9e06o4b8etpi)

✅ Closes: ICU-5241

* refactor: 💡 refactored `models/worker.js`

Because `canonical_tags` and `config_tags` are `readOnly` attributes, we
could use `attr` decorator instead of `fragment`.

✅ Closes: ICU-5241

* refactored `model/worker.js and deleted un-needed files

* refactor: 💡 Refactored model/worker.js and created test

Refactored model/worker.js to include custom method for POST route for
adding new worker.

BREAKING CHANGE: 🧨 no

✅ Closes: ICU-5241

* refactor: 💡 Refactored custom POST route method for worker

Refactored custom method on `model/worker.js` to include serialization
for `worker_genrated_auth_token`

BREAKING CHANGE: 🧨 no

✅ Closes: ICU-5241

* refactor: 💡 Refactor test

Refactor model/worker-test.js and serializers/worker.js

BREAKING CHANGE: 🧨 no

✅ Closes: ICU-5241

* Update addons/api/addon/serializers/worker.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

* update worker.js documentation block

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
2022-08-09 15:34:42 -04:00

44 lines
1.4 KiB
JavaScript

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | worker', function (hooks) {
setupTest(hooks);
test('it serializes normally without adapterOptions.workerGeneratedAuthToken', function (assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('worker');
const record = store.createRecord('worker', {
name: 'worker',
description: 'Description',
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
version: 1,
description: 'Description',
name: 'worker',
});
});
test('it serializes using `adapterOptions.workerGeneratedAuthToken`', function (assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('worker');
const record = store.createRecord('worker', {
name: 'worker',
description: 'Description',
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
workerGeneratedAuthToken: '123-abc',
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
version: 1,
worker_generated_auth_token: '123-abc',
});
});
});