refactor: Remove serializeWithNewPassword adapteroptions
This commit is contained in:
3 files changed
+15
-12
No files matched your search
@@ -19,10 +19,9 @@ export default class AccountModel extends GeneratedAccountModel {
|
||||
* @param {object} options.adapterOptions
|
||||
* @return {Promise}
|
||||
*/
|
||||
savePassword(password, options={ adapterOptions: {} }) {
|
||||
setPassword(password, options={ adapterOptions: {} }) {
|
||||
const defaultAdapterOptions = {
|
||||
method: 'set-password',
|
||||
serializeWithNewPassword: true,
|
||||
password
|
||||
};
|
||||
return this.save({
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { get } from '@ember/object';
|
||||
|
||||
export default class AccountSerializer extends ApplicationSerializer {
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* If `adapterOptions.serializeWithNewPassword` is true, the serialization should
|
||||
* include **password** and the version.
|
||||
* If `adapterOptions.method` is `set-password`, the serialization should
|
||||
* include only **password** and the version.
|
||||
* If `adapterOptions.password` is set, the serialization should
|
||||
* include **password** in it's `attributes`.
|
||||
* @override
|
||||
@@ -15,11 +14,12 @@ export default class AccountSerializer extends ApplicationSerializer {
|
||||
* @return {object}
|
||||
*/
|
||||
serialize(snapshot) {
|
||||
const password = get(snapshot, 'adapterOptions.password');
|
||||
const serializeWithNewPassword = get(snapshot, 'adapterOptions.serializeWithNewPassword');
|
||||
const password = snapshot?.adapterOptions?.password;
|
||||
let serialized = super.serialize(...arguments);
|
||||
if (password) serialized.attributes.password = password;
|
||||
if (serializeWithNewPassword) serialized = this.serializeWithNewPassword(snapshot, password)
|
||||
if (password && snapshot?.record?.isNew) serialized.attributes.password = password;
|
||||
if (snapshot?.adapterOptions?.method === 'set-password') {
|
||||
serialized = this.serializeForSetPassword(snapshot, password);
|
||||
}
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export default class AccountSerializer extends ApplicationSerializer {
|
||||
* @param {string} password
|
||||
* @return {object}
|
||||
*/
|
||||
serializeWithNewPassword(snapshot, password) {
|
||||
serializeForSetPassword(snapshot, password) {
|
||||
return {
|
||||
version: snapshot.attr('version'),
|
||||
password,
|
||||
|
||||
@@ -65,7 +65,11 @@ module('Unit | Serializer | account', function(hooks) {
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes only password when `adapterOptions.serializeWithNewPassword` is true', function (assert) {
|
||||
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');
|
||||
@@ -81,7 +85,7 @@ module('Unit | Serializer | account', function(hooks) {
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
snapshot.adapterOptions = {
|
||||
serializeWithNewPassword: true,
|
||||
method: 'set-password',
|
||||
password: 'Password'
|
||||
};
|
||||
const serializedRecord = serializer.serialize(snapshot);
|
||||
|
||||
Reference in new issue
Block a user