Skip to content
Open
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
10 changes: 5 additions & 5 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
> v0.2.0 ~ "First-class trailers, inspections and full test coverage"
> v0.2.1 ~ "Inspection display dates"

---
## Highlights

- **First-class Trailer data models** — trailer models, serializers and data contracts for the console, with current trailers embedded on the vehicle serializer.
- **Inspection data models** — models and serializers backing the maintenance platform upgrade.
- **`is-waypoint-record` util** — moved out of `ember-core` and into this package.
- **Test coverage campaign** — a 100% coverage gate wired into CI, with Codecov reporting.
- **Inspection display dates are formatted** — `inspection-form` and `inspection-submission` format their display-date getters as `yyyy-MM-dd HH:mm` and answer `null` for a date they cannot read, the way every other model in this package does. The console's inspection indexes were showing a raw datetime instance string.
- **`frequency` is gone from `inspection-form`** — nothing scheduled an inspection from it, and it is being dropped from the FleetOps API resource, report schema and console in fleetbase/fleetops#319.

The underscored attributes (`created_at`, `published_at`, …) are untouched, so anything needing a real `Date` is unaffected.

---
## Need help?
Expand Down
32 changes: 25 additions & 7 deletions addon/models/inspection-form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate } from 'date-fns';

export default class InspectionFormModel extends Model {
@attr('string') uuid;
Expand All @@ -10,7 +12,6 @@ export default class InspectionFormModel extends Model {
@attr('string') description;
@attr('string') type;
@attr('string') status;
@attr('string') frequency;
@belongsTo('maintenance-subject', { polymorphic: true, async: false }) subject;
@attr('raw') items;
@attr('raw') settings;
Expand All @@ -25,15 +26,32 @@ export default class InspectionFormModel extends Model {
return this.name || this.public_id;
}

get createdAt() {
return this.created_at;
/**
* The display dates a table or a details panel reads. They returned the
* raw `Date`, which rendered as a full datetime instance string in a
* column; every other model in this package formats them here.
*/
@computed('created_at') get createdAt() {
if (!isValidDate(this.created_at)) {
return null;
}

return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}

get updatedAt() {
return this.updated_at;
@computed('updated_at') get updatedAt() {
if (!isValidDate(this.updated_at)) {
return null;
}

return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}

get publishedAt() {
return this.published_at;
@computed('published_at') get publishedAt() {
if (!isValidDate(this.published_at)) {
return null;
}

return formatDate(this.published_at, 'yyyy-MM-dd HH:mm');
}
}
39 changes: 31 additions & 8 deletions addon/models/inspection-submission.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate } from 'date-fns';

export default class InspectionSubmissionModel extends Model {
@attr('string') uuid;
Expand Down Expand Up @@ -43,19 +45,40 @@ export default class InspectionSubmissionModel extends Model {
return this.public_id || this.form_name || 'Inspection';
}

get createdAt() {
return this.created_at;
/**
* The display dates a table or a details panel reads — formatted here, as
* in every other model in this package, rather than handed out as a raw
* `Date` that renders as a full datetime instance string.
*/
@computed('created_at') get createdAt() {
if (!isValidDate(this.created_at)) {
return null;
}

return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}

get updatedAt() {
return this.updated_at;
@computed('updated_at') get updatedAt() {
if (!isValidDate(this.updated_at)) {
return null;
}

return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}

get submittedAt() {
return this.submitted_at;
@computed('submitted_at') get submittedAt() {
if (!isValidDate(this.submitted_at)) {
return null;
}

return formatDate(this.submitted_at, 'yyyy-MM-dd HH:mm');
}

get resolvedAt() {
return this.resolved_at;
@computed('resolved_at') get resolvedAt() {
if (!isValidDate(this.resolved_at)) {
return null;
}

return formatDate(this.resolved_at, 'yyyy-MM-dd HH:mm');
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/fleetops-data",
"version": "0.2.0",
"version": "0.2.1",
"description": "Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.",
"keywords": [
"fleetbase-data",
Expand Down
29 changes: 20 additions & 9 deletions tests/unit/models/inspection-form-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupTest } from 'dummy/tests/helpers';
import { assertAttributeTypes, assertRelationships } from 'dummy/tests/helpers/model-contract';
import { FIXED_DATE_LONG, assertAttributeTypes, assertDateGetters, assertRelationships } from 'dummy/tests/helpers/model-contract';

module('Unit | Model | inspection-form', function (hooks) {
setupTest(hooks);
Expand Down Expand Up @@ -37,14 +37,25 @@ module('Unit | Model | inspection-form', function (hooks) {
assert.strictEqual(form.displayName, 'Pre-trip');
});

test('the camelCase date getters expose the raw dates', function (assert) {
const published = new Date(2026, 8, 1);
const created = new Date(2026, 7, 1);
const updated = new Date(2026, 7, 2);
const form = this.store.createRecord('inspection-form', { published_at: published, created_at: created, updated_at: updated });
test('it no longer declares a frequency attribute', function (assert) {
assert.notOk(this.store.modelFor('inspection-form').attributes.has('frequency'), 'inspection-form does not declare `frequency`');
});

test('published_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-form'), 'published_at', {
publishedAt: FIXED_DATE_LONG,
});
});

assert.strictEqual(form.publishedAt, published);
assert.strictEqual(form.createdAt, created);
assert.strictEqual(form.updatedAt, updated);
test('created_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-form'), 'created_at', {
createdAt: FIXED_DATE_LONG,
});
});

test('updated_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-form'), 'updated_at', {
updatedAt: FIXED_DATE_LONG,
});
});
});
33 changes: 22 additions & 11 deletions tests/unit/models/inspection-submission-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupTest } from 'dummy/tests/helpers';
import { assertAttributeTypes, assertRelationships } from 'dummy/tests/helpers/model-contract';
import { FIXED_DATE_LONG, assertAttributeTypes, assertDateGetters, assertRelationships } from 'dummy/tests/helpers/model-contract';

module('Unit | Model | inspection-submission', function (hooks) {
setupTest(hooks);
Expand Down Expand Up @@ -50,16 +50,27 @@ module('Unit | Model | inspection-submission', function (hooks) {
assert.strictEqual(submission.displayName, 'submission_1');
});

test('the camelCase date getters expose the raw dates', function (assert) {
const submitted = new Date(2026, 8, 1);
const resolved = new Date(2026, 8, 2);
const created = new Date(2026, 7, 1);
const updated = new Date(2026, 7, 2);
const submission = this.store.createRecord('inspection-submission', { submitted_at: submitted, resolved_at: resolved, created_at: created, updated_at: updated });
test('submitted_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-submission'), 'submitted_at', {
submittedAt: FIXED_DATE_LONG,
});
});

test('resolved_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-submission'), 'resolved_at', {
resolvedAt: FIXED_DATE_LONG,
});
});

assert.strictEqual(submission.submittedAt, submitted);
assert.strictEqual(submission.resolvedAt, resolved);
assert.strictEqual(submission.createdAt, created);
assert.strictEqual(submission.updatedAt, updated);
test('created_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-submission'), 'created_at', {
createdAt: FIXED_DATE_LONG,
});
});

test('updated_at renders its formatting getter', function (assert) {
assertDateGetters(assert, this.store.createRecord('inspection-submission'), 'updated_at', {
updatedAt: FIXED_DATE_LONG,
});
});
});
Loading