Files
threshold-ui/addons/api/tests/unit/serializers/account-test.js
T

125 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-09-15 11:00:00 -04:00
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
2020-09-16 14:29:02 -04:00
module('Unit | Serializer | account', function (hooks) {
2020-09-15 11:00:00 -04:00
setupTest(hooks);
test('it serializes normally', function (assert) {
2020-09-15 11:00:00 -04:00
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account');
const record = store.createRecord('account', {
type: 'password',
name: 'Name',
auth_method_id: '1',
2020-09-15 11:00:00 -04:00
description: 'Description',
attributes: {
login_name: 'Login Name',
},
2020-09-16 14:29:02 -04:00
version: 1,
2020-09-15 11:00:00 -04:00
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
type: 'password',
name: 'Name',
auth_method_id: '1',
description: 'Description',
attributes: {
2020-09-16 14:29:02 -04:00
login_name: 'Login Name',
},
2020-09-16 14:29:02 -04:00
version: 1,
});
});
test('it serializes password attribute when `adapterOptions.password` is true', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account');
const record = store.createRecord('account', {
type: 'password',
name: 'Name',
auth_method_id: '1',
2020-09-15 11:00:00 -04:00
description: 'Description',
attributes: {
login_name: 'Login Name',
},
2020-09-16 14:29:02 -04:00
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
2020-09-16 14:29:02 -04:00
password: 'Password',
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
type: 'password',
name: 'Name',
2020-09-15 11:00:00 -04:00
auth_method_id: '1',
description: 'Description',
attributes: {
login_name: 'Login Name',
2020-09-16 14:29:02 -04:00
password: 'Password',
},
2020-09-16 14:29:02 -04:00
version: 1,
2020-09-15 11:00:00 -04:00
});
});
test('it does not serialize password for non-new records', function (assert) {
assert.expect(0);
});
test('it serializes only password when `adapterOptions.method` is set to `set-password`', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account');
const record = store.createRecord('account', {
type: 'password',
name: 'Name',
description: 'Description',
attributes: {
2020-09-16 14:29:02 -04:00
login_name: 'Login Name',
},
auth_method_id: '1',
2020-09-16 14:29:02 -04:00
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
method: 'set-password',
2020-09-16 14:29:02 -04:00
password: 'Password',
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
password: 'Password',
2020-09-16 14:29:02 -04:00
version: 1,
});
});
2020-09-16 14:56:52 -04:00
test('it serializes a custom payload when `adapterOptions.method` is set to `change-password`', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('account');
const record = store.createRecord('account', {
type: 'password',
name: 'Name',
description: 'Description',
attributes: {
login_name: 'Login Name',
},
auth_method_id: '1',
version: 1,
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
method: 'change-password',
currentPassword: 'Current',
newPassword: 'New',
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
current_password: 'Current',
new_password: 'New',
version: 1,
});
});
2020-09-15 11:00:00 -04:00
});