test: Add missing account serializer test
Delete account password attribute in mirage to mimic API exactly
This commit is contained in:
3 files changed
+39
-11
No files matched your search
@@ -4,21 +4,10 @@ import { setupTest } from 'ember-qunit';
|
||||
module('Unit | Model | account', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('account', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
|
||||
test('it contains attributes', function(assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('account', {
|
||||
type: 'password',
|
||||
attributes: {
|
||||
login_name: 'loginname'
|
||||
}
|
||||
});
|
||||
assert.equal(model.attributes.login_name, 'loginname');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Serializer | account', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it serializes account', 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',
|
||||
password: 'Password',
|
||||
},
|
||||
auth_method_id: '1',
|
||||
version: 1
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
snapshot.adapterOptions = {};
|
||||
const serializedRecord = serializer.serialize(snapshot);
|
||||
assert.deepEqual(serializedRecord, {
|
||||
type: 'password',
|
||||
name: 'Name',
|
||||
description: 'Description',
|
||||
attributes: {
|
||||
login_name: 'Login Name',
|
||||
password: 'Password',
|
||||
},
|
||||
auth_method_id: '1',
|
||||
version: 1
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -6,6 +6,7 @@ export default ApplicationSerializer.extend({
|
||||
_hashForModel(model) {
|
||||
const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments);
|
||||
json.auth_method_id = model.authMethodId;
|
||||
delete json.attributes?.password;
|
||||
return json;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user