e9e52e0dfe
This doesn’t include Ember Data, as we are still back on 3.12. Most changes are deprecation updates, linting fixes, and dependencies. It can be read commit-by-commit, though many of them are mechanical and skimmable. For the new linting exclusions, I’ve added them to the Tech Debt list. The decrease in test count is because linting is no longer included in ember test. There’s a new deprecation warning in the logs that can be fixed by updating Ember Power Select but when I tried that it caused it to render incorrectly, so I decided to ignore it for now and address it separately.
108 lines
2.6 KiB
JavaScript
108 lines
2.6 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
import ApplicationSerializer from 'nomad-ui/serializers/application';
|
|
|
|
import Model from '@ember-data/model';
|
|
import { attr } from '@ember-data/model';
|
|
|
|
class TestSerializer extends ApplicationSerializer {
|
|
arrayNullOverrides = ['Things'];
|
|
|
|
mapToArray = [
|
|
'ArrayableMap',
|
|
{ beforeName: 'OriginalNameArrayableMap', afterName: 'RenamedArrayableMap' },
|
|
];
|
|
|
|
separateNanos = ['Time'];
|
|
}
|
|
|
|
class TestModel extends Model {
|
|
@attr() things;
|
|
|
|
@attr() arrayableMap;
|
|
@attr() renamedArrayableMap;
|
|
|
|
@attr() time;
|
|
@attr() timeNanos;
|
|
}
|
|
|
|
module('Unit | Serializer | Application', function(hooks) {
|
|
setupTest(hooks);
|
|
|
|
hooks.beforeEach(function() {
|
|
this.store = this.owner.lookup('service:store');
|
|
this.owner.register('model:test', TestModel);
|
|
this.owner.register('serializer:test', TestSerializer);
|
|
|
|
this.subject = () => this.store.serializerFor('test');
|
|
});
|
|
|
|
const normalizationTestCases = [
|
|
{
|
|
name: 'Null array and maps',
|
|
in: {
|
|
ID: 'test-test',
|
|
Things: null,
|
|
ArrayableMap: null,
|
|
OriginalNameArrayableMap: null,
|
|
Time: 1607839992000100000,
|
|
},
|
|
out: {
|
|
data: {
|
|
id: 'test-test',
|
|
attributes: {
|
|
things: [],
|
|
arrayableMap: [],
|
|
renamedArrayableMap: [],
|
|
time: 1607839992000,
|
|
timeNanos: 100096,
|
|
},
|
|
relationships: {},
|
|
type: 'test',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: 'Non-null array and maps',
|
|
in: {
|
|
ID: 'test-test',
|
|
Things: [1, 2, 3],
|
|
ArrayableMap: {
|
|
b: { Order: 2 },
|
|
a: { Order: 1 },
|
|
'c.d': { Order: 3 },
|
|
},
|
|
OriginalNameArrayableMap: {
|
|
a: { X: 1 },
|
|
},
|
|
Time: 1607839992000100000,
|
|
SomethingExtra: 'xyz',
|
|
},
|
|
out: {
|
|
data: {
|
|
id: 'test-test',
|
|
attributes: {
|
|
things: [1, 2, 3],
|
|
arrayableMap: [
|
|
{ Name: 'a', Order: 1 },
|
|
{ Name: 'b', Order: 2 },
|
|
{ Name: 'c.d', Order: 3 },
|
|
],
|
|
renamedArrayableMap: [{ Name: 'a', X: 1 }],
|
|
time: 1607839992000,
|
|
timeNanos: 100096,
|
|
},
|
|
relationships: {},
|
|
type: 'test',
|
|
},
|
|
},
|
|
},
|
|
];
|
|
|
|
normalizationTestCases.forEach(testCase => {
|
|
test(`normalization: ${testCase.name}`, async function(assert) {
|
|
assert.deepEqual(this.subject().normalize(TestModel, testCase.in), testCase.out);
|
|
});
|
|
});
|
|
});
|