Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/models/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class OrderModel extends Model {

/** @relationships */
@belongsTo('company') company;
@belongsTo('order-config') order_config;
@belongsTo('order-config', { async: false }) order_config;
@belongsTo('customer', { polymorphic: true, async: false }) customer;
@belongsTo('facilitator', { polymorphic: true, async: false }) facilitator;
@belongsTo('transaction', { async: false }) transaction;
Expand Down
10 changes: 10 additions & 0 deletions addon/serializers/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
*/
serialize(snapshot, options) {
const json = super.serialize(snapshot, options);
const selectedOrderConfigUuid = snapshot.attr('order_config_uuid');
const selectedType = snapshot.attr('type');
const unshiftAttributes = [
'order_config',
'driver_name',
Expand All @@ -59,6 +61,14 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
delete json[attr];
});

if (!isBlank(selectedOrderConfigUuid)) {
json.order_config_uuid = selectedOrderConfigUuid;
}

if (!isBlank(selectedType)) {
json.type = selectedType;
}

return json;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/models/order-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ module('Unit | Model | order', function (hooks) {
let model = store.createRecord('order', {});
assert.ok(model);
});

test('order config is embedded synchronously', function (assert) {
let store = this.owner.lookup('service:store');
let relationship = store.modelFor('order').relationshipsByName.get('order_config');

assert.strictEqual(relationship.options.async, false);
});
});
35 changes: 35 additions & 0 deletions tests/unit/serializers/order-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,39 @@ module('Unit | Serializer | order', function (hooks) {

assert.ok(serializedRecord);
});

test('selected order config scalar fields win over a stale relationship snapshot', function (assert) {
let store = this.owner.lookup('service:store');
let transport = store.push({
data: {
type: 'order-config',
id: 'transport-config-uuid',
attributes: {
key: 'transport',
name: 'Transport',
},
},
});
let haulage = store.push({
data: {
type: 'order-config',
id: 'haulage-config-uuid',
attributes: {
key: 'haulage',
name: 'Haulage',
},
},
});
let record = store.createRecord('order', {
order_config: transport,
order_config_uuid: haulage.id,
type: haulage.key,
});

let serializedRecord = record.serialize();

assert.strictEqual(serializedRecord.order_config_uuid, haulage.id);
assert.strictEqual(serializedRecord.type, haulage.key);
assert.notOk(serializedRecord.order_config);
});
});
Loading