From a0105c60841731b98ad8ff44d4e6a7417ed0de43 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Fri, 7 Aug 2026 13:01:59 +0800 Subject: [PATCH] Add is-waypoint-record util MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved here from @fleetbase/ember-core, where it had been importing ../models/waypoint — a path that does not exist in that package, so the module threw for anyone who imported it. This is its natural home: the Waypoint model lives here, so the import is a plain relative one. It could not stay in ember-core, because ember-core cannot depend on fleetops-data (fleetops-data already depends on ember-core), leaving only an undeclared cross-package import or an optional peer dependency, both worse than putting the util beside the model it checks. No package used it in source, so nothing needs updating alongside this. The matches that show up elsewhere are in built dist bundles, which is ember-core's own code inlined into consumers' vendor files rather than real usage. Tested against a real waypoint, the place model waypoint extends, an unrelated record, a proxy, and plain and nullish values. Co-Authored-By: Claude Fable 5 --- addon/utils/is-waypoint-record.js | 5 +++ app/utils/is-waypoint-record.js | 1 + tests/unit/utils/is-waypoint-record-test.js | 47 +++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 addon/utils/is-waypoint-record.js create mode 100644 app/utils/is-waypoint-record.js create mode 100644 tests/unit/utils/is-waypoint-record-test.js diff --git a/addon/utils/is-waypoint-record.js b/addon/utils/is-waypoint-record.js new file mode 100644 index 0000000..57d8025 --- /dev/null +++ b/addon/utils/is-waypoint-record.js @@ -0,0 +1,5 @@ +import WaypointModel from '../models/waypoint'; + +export default function isWaypointRecord(record) { + return record instanceof WaypointModel; +} diff --git a/app/utils/is-waypoint-record.js b/app/utils/is-waypoint-record.js new file mode 100644 index 0000000..65c9b8f --- /dev/null +++ b/app/utils/is-waypoint-record.js @@ -0,0 +1 @@ +export { default } from '@fleetbase/fleetops-data/utils/is-waypoint-record'; diff --git a/tests/unit/utils/is-waypoint-record-test.js b/tests/unit/utils/is-waypoint-record-test.js new file mode 100644 index 0000000..3ab5538 --- /dev/null +++ b/tests/unit/utils/is-waypoint-record-test.js @@ -0,0 +1,47 @@ +import isWaypointRecord from 'dummy/utils/is-waypoint-record'; +import WaypointModel from 'dummy/models/waypoint'; +import PlaceModel from 'dummy/models/place'; +import { module, test } from 'qunit'; +import { setupTest } from 'dummy/tests/helpers'; +import ObjectProxy from '@ember/object/proxy'; + +module('Unit | Utility | is-waypoint-record', function (hooks) { + setupTest(hooks); + + hooks.beforeEach(function () { + this.store = this.owner.lookup('service:store'); + }); + + test('it returns true for a waypoint record', function (assert) { + assert.true(isWaypointRecord(this.store.createRecord('waypoint', {}))); + }); + + test('it returns false for a place, which waypoint extends', function (assert) { + // WaypointModel extends PlaceModel, so the check has to be narrow enough + // to reject the parent while still accepting the child. + assert.true(WaypointModel.prototype instanceof PlaceModel, 'waypoint does extend place'); + assert.false(isWaypointRecord(this.store.createRecord('place', {}))); + }); + + test('it returns false for an unrelated record', function (assert) { + assert.false(isWaypointRecord(this.store.createRecord('order', {}))); + }); + + test('it returns false for a proxy wrapping a waypoint', function (assert) { + const record = this.store.createRecord('waypoint', {}); + + assert.false(isWaypointRecord(ObjectProxy.create({ content: record })), 'instanceof looks at the proxy, not its content'); + }); + + test('it returns false for plain and nullish values', function (assert) { + assert.false(isWaypointRecord({})); + assert.false(isWaypointRecord(null)); + assert.false(isWaypointRecord(undefined)); + assert.false(isWaypointRecord('waypoint')); + assert.false(isWaypointRecord([])); + }); + + test('it returns false for an object merely shaped like a waypoint', function (assert) { + assert.false(isWaypointRecord({ place: {}, order: 1 }), 'the check is by identity, not by shape'); + }); +});