Fix Users page not updating fields correctly (#1105)
* fix: 🐛 Normalize update responses to track removed fields ✅ Closes: ICU-4189
This commit is contained in:
1 parent
7e792d3f76
commit
97196368cb
6 files changed
+118
-4
No files matched your search
@@ -115,4 +115,39 @@ module('Unit | Model | user', function (hooks) {
|
||||
'User has empty account_ids by default'
|
||||
);
|
||||
});
|
||||
|
||||
test('it defaults to null for readonly attributes when response does not have fields', async function (assert) {
|
||||
assert.expect(3);
|
||||
this.server.post('/v1/users/123abc:remove-accounts', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
account_ids: ['3'],
|
||||
version: 1,
|
||||
});
|
||||
return { id: '123abc', name: 'newName' };
|
||||
});
|
||||
const store = this.owner.lookup('service:store');
|
||||
store.push({
|
||||
data: {
|
||||
id: '123abc',
|
||||
type: 'user',
|
||||
attributes: {
|
||||
name: 'user',
|
||||
description: 'Description',
|
||||
account_ids: ['3'],
|
||||
version: 1,
|
||||
login_name: 'zed',
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('user', '123abc');
|
||||
await model.removeAccount('3');
|
||||
|
||||
assert.equal(model.login_name, null);
|
||||
assert.equal(model.name, 'newName');
|
||||
});
|
||||
});
|
||||
@@ -211,4 +211,41 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('it normalizes removed fields correctly', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('user');
|
||||
const user = store.createRecord('user').constructor;
|
||||
const payload = {
|
||||
id: '1',
|
||||
name: 'user 1',
|
||||
scope: { id: 'o_123' },
|
||||
};
|
||||
const normalized = serializer.normalizeUpdateRecordResponse(
|
||||
store,
|
||||
user,
|
||||
payload
|
||||
);
|
||||
assert.deepEqual(normalized, {
|
||||
included: [],
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'user',
|
||||
attributes: {
|
||||
authorized_actions: [],
|
||||
name: 'user 1',
|
||||
scope: { scope_id: 'o_123' },
|
||||
account_ids: [],
|
||||
authorized_collection_actions: null,
|
||||
created_time: null,
|
||||
email: null,
|
||||
full_name: null,
|
||||
login_name: null,
|
||||
updated_time: null,
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user