From e9e15c6438dd821175d95fbd0e901e590dabd808 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Tue, 11 Feb 2025 14:28:30 -0800 Subject: [PATCH] chore: fixup deprecation-removed test variants (#9677) * chore: fixup TODO tests * fix todo test --- .../-private/managers/notification-manager.ts | 2 +- .../mutating-has-many-test-infra.ts | 10 +- .../unit/model/relationships/has-many-test.js | 596 ++++++++++++------ 3 files changed, 419 insertions(+), 189 deletions(-) diff --git a/packages/store/src/-private/managers/notification-manager.ts b/packages/store/src/-private/managers/notification-manager.ts index 7268a1321d2..b74fe6eaaf9 100644 --- a/packages/store/src/-private/managers/notification-manager.ts +++ b/packages/store/src/-private/managers/notification-manager.ts @@ -54,7 +54,7 @@ function count(label: string) { globalThis.counts = globalThis.counts || {}; // @ts-expect-error // eslint-disable-next-line - wglobalThis.counts[label] = (globalThis.counts[label] || 0) + 1; + globalThis.counts[label] = (globalThis.counts[label] || 0) + 1; } function _unsubscribe( diff --git a/tests/main/tests/integration/relationships/collection/mutating-has-many-test-infra.ts b/tests/main/tests/integration/relationships/collection/mutating-has-many-test-infra.ts index 6ff904ae7fa..86dfc4f6979 100644 --- a/tests/main/tests/integration/relationships/collection/mutating-has-many-test-infra.ts +++ b/tests/main/tests/integration/relationships/collection/mutating-has-many-test-infra.ts @@ -16,12 +16,6 @@ import { Type } from '@warp-drive/core-types/symbols'; import type { ReactiveContext } from '../../../helpers/reactive-context'; import { reactiveContext } from '../../../helpers/reactive-context'; -let IS_DEPRECATE_MANY_ARRAY_DUPLICATES = false; - -if (DEPRECATE_MANY_ARRAY_DUPLICATES) { - IS_DEPRECATE_MANY_ARRAY_DUPLICATES = true; -} - class User extends Model { @attr declare name: string; @hasMany('user', { async: false, inverse: 'friends' }) declare friends: ManyArray; @@ -222,8 +216,8 @@ async function applyMutation( const result = generateAppliedMutation(store, record, mutation); const initialIds = record.friends.map((f) => f.id).join(','); - const shouldError = result.hasDuplicates && !IS_DEPRECATE_MANY_ARRAY_DUPLICATES; - const shouldDeprecate = result.hasDuplicates && IS_DEPRECATE_MANY_ARRAY_DUPLICATES; + const shouldError = result.hasDuplicates && /* inline-macro-config */ !DEPRECATE_MANY_ARRAY_DUPLICATES; + const shouldDeprecate = result.hasDuplicates && /* inline-macro-config */ DEPRECATE_MANY_ARRAY_DUPLICATES; const expected = shouldError ? result.unchanged : result.deduped; try { diff --git a/tests/main/tests/unit/model/relationships/has-many-test.js b/tests/main/tests/unit/model/relationships/has-many-test.js index a5e76f97a2c..3d8b6bd4c40 100644 --- a/tests/main/tests/unit/model/relationships/has-many-test.js +++ b/tests/main/tests/unit/model/relationships/has-many-test.js @@ -12,6 +12,7 @@ import { recordIdentifierFor } from '@ember-data/store'; import { deprecatedTest } from '@ember-data/unpublished-test-infra/test-support/deprecated-test'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; import todo from '@ember-data/unpublished-test-infra/test-support/todo'; +import { DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE } from '@warp-drive/build-config/deprecations'; module('unit/model/relationships - hasMany', function (hooks) { setupTest(hooks); @@ -1368,236 +1369,471 @@ module('unit/model/relationships - hasMany', function (hooks) { ); }); - todo( - '[push hasMany] new items added to a hasMany relationship are not cleared by a store.push', - async function (assert) { - assert.expect(5); + if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) { + todo( + '[push hasMany] new items added to a hasMany relationship are not cleared by a store.push', + async function (assert) { + assert.expect(5); - const Person = Model.extend({ - name: attr('string'), - pets: hasMany('pet', { async: false, inverse: null }), - }); + class Person extends Model { + @attr name; + @hasMany('pet', { async: false, inverse: null }) + pets; + } - const Pet = Model.extend({ - name: attr('string'), - person: belongsTo('person', { async: false, inverse: null }), - }); + class Pet extends Model { + @attr name; + @belongsTo('person', { async: false, inverse: null }) + person; + } - this.owner.register('model:person', Person); - this.owner.register('model:pet', Pet); + this.owner.register('model:person', Person); + this.owner.register('model:pet', Pet); - const store = this.owner.lookup('service:store'); - const adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - adapter.shouldBackgroundReloadRecord = () => false; - adapter.deleteRecord = () => { - return Promise.resolve({ data: null }); - }; + adapter.shouldBackgroundReloadRecord = () => false; + adapter.deleteRecord = () => { + return Promise.resolve({ data: null }); + }; - store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Chris Thoburn', - }, - relationships: { - pets: { - data: [{ type: 'pet', id: '1' }], + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, }, }, - }, - included: [ - { - type: 'pet', + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', + }, + }, + ], + }); + + const person = store.peekRecord('person', '1'); + const pets = await person.pets; + + const shen = pets.at(0); + const rebel = store.peekRecord('pet', '3'); + + assert.strictEqual(shen.name, 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map((p) => p.id), + ['1'], + 'precond - relationship has the correct pets to start' + ); + + pets.push(rebel); + await settled(); + + assert.deepEqual( + pets.map((p) => p.id), + ['1', '3'], + 'precond2 - relationship now has the correct two pets' + ); + + store.push({ + data: { + type: 'person', id: '1', - attributes: { - name: 'Shenanigans', + relationships: { + pets: { + data: [{ type: 'pet', id: '2' }], + }, }, }, - { - type: 'pet', - id: '2', + }); + + const hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; + + assert.todo.deepEqual( + pets.map((p) => p.id), + ['2', '3'], + 'relationship now has the correct current pets' + ); + assert.deepEqual( + hasManyCanonical.map((p) => p.id), + ['2'], + 'relationship now has the correct canonical pets' + ); + } + ); + + todo( + '[push hasMany] items removed from a hasMany relationship are not cleared by a store.push', + async function (assert) { + assert.expect(5); + + class Person extends Model { + @attr name; + @hasMany('pet', { async: false, inverse: null }) + pets; + } + + class Pet extends Model { + @attr name; + @belongsTo('person', { async: false, inverse: null }) + person; + } + + this.owner.register('model:person', Person); + this.owner.register('model:pet', Pet); + + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.deleteRecord = () => { + return Promise.resolve({ data: null }); + }; + + store.push({ + data: { + type: 'person', + id: '1', attributes: { - name: 'Rambunctious', + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [ + { type: 'pet', id: '1' }, + { type: 'pet', id: '3' }, + ], + }, }, }, - { - type: 'pet', - id: '3', - attributes: { - name: 'Rebel', + included: [ + { + type: 'pet', + id: '1', + attributes: { + name: 'Shenanigans', + }, + }, + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', + }, + }, + ], + }); + + const person = store.peekRecord('person', '1'); + const pets = person.pets; + + const shen = pets.at(0); + const rebel = store.peekRecord('pet', '3'); + + assert.strictEqual(shen.name, 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map((p) => p.id), + ['1', '3'], + 'precond - relationship has the correct pets to start' + ); + + pets.splice(pets.indexOf(rebel), 1); + + assert.deepEqual( + pets.map((p) => p.id), + ['1'], + 'precond2 - relationship now has the correct pet' + ); + + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + pets: { + data: [ + { type: 'pet', id: '2' }, + { type: 'pet', id: '3' }, + ], + }, }, }, - ], - }); + }); - const person = store.peekRecord('person', '1'); - const pets = await person.pets; + const hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; + + assert.todo.deepEqual( + pets.map((p) => p.id), + ['2'], + 'relationship now has the correct current pets' + ); + assert.deepEqual( + hasManyCanonical.map((p) => p.id), + ['2', '3'], + 'relationship now has the correct canonical pets' + ); + } + ); + } - const shen = pets.at(0); - const rebel = store.peekRecord('pet', '3'); + test('[push hasMany] new items added to a hasMany relationship are not cleared by a store.push', async function (assert) { + assert.expect(5); - assert.strictEqual(shen.name, 'Shenanigans', 'precond - relationships work'); - assert.deepEqual( - pets.map((p) => p.id), - ['1'], - 'precond - relationship has the correct pets to start' - ); + class Person extends Model { + @attr name; + @hasMany('pet', { async: false, inverse: null, resetOnRemoteUpdate: false }) + pets; + } - pets.push(rebel); - await settled(); + class Pet extends Model { + @attr name; + @belongsTo('person', { async: false, inverse: null }) + person; + } - assert.deepEqual( - pets.map((p) => p.id), - ['1', '3'], - 'precond2 - relationship now has the correct two pets' - ); + this.owner.register('model:person', Person); + this.owner.register('model:pet', Pet); - store.push({ - data: { - type: 'person', + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.deleteRecord = () => { + return Promise.resolve({ data: null }); + }; + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [{ type: 'pet', id: '1' }], + }, + }, + }, + included: [ + { + type: 'pet', id: '1', - relationships: { - pets: { - data: [{ type: 'pet', id: '2' }], - }, + attributes: { + name: 'Shenanigans', }, }, - }); + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', + }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', + }, + }, + ], + }); - const hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; + const person = store.peekRecord('person', '1'); + const pets = await person.pets; - assert.todo.deepEqual( - pets.map((p) => p.id), - ['2', '3'], - 'relationship now has the correct current pets' - ); - assert.deepEqual( - hasManyCanonical.map((p) => p.id), - ['2'], - 'relationship now has the correct canonical pets' - ); - } - ); + const shen = pets.at(0); + const rebel = store.peekRecord('pet', '3'); - todo( - '[push hasMany] items removed from a hasMany relationship are not cleared by a store.push', - async function (assert) { - assert.expect(5); + assert.strictEqual(shen.name, 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map((p) => p.id), + ['1'], + 'precond - relationship has the correct pets to start' + ); - const Person = Model.extend({ - name: attr('string'), - pets: hasMany('pet', { async: false, inverse: null }), - }); + pets.push(rebel); + await settled(); - const Pet = Model.extend({ - name: attr('string'), - person: belongsTo('person', { async: false, inverse: null }), - }); + assert.deepEqual( + pets.map((p) => p.id), + ['1', '3'], + 'precond2 - relationship now has the correct two pets' + ); - this.owner.register('model:person', Person); - this.owner.register('model:pet', Pet); + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + pets: { + data: [{ type: 'pet', id: '2' }], + }, + }, + }, + }); - const store = this.owner.lookup('service:store'); - const adapter = store.adapterFor('application'); + const hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; - adapter.shouldBackgroundReloadRecord = () => false; - adapter.deleteRecord = () => { - return Promise.resolve({ data: null }); - }; + assert.deepEqual( + pets.map((p) => p.id), + ['2', '3'], + 'relationship now has the correct current pets' + ); + assert.deepEqual( + hasManyCanonical.map((p) => p.id), + ['2'], + 'relationship now has the correct canonical pets' + ); + }); - store.push({ - data: { - type: 'person', + test('[push hasMany] items removed from a hasMany relationship are not cleared by a store.push', async function (assert) { + assert.expect(5); + + class Person extends Model { + @attr name; + @hasMany('pet', { async: false, inverse: null, resetOnRemoteUpdate: false }) + pets; + } + + class Pet extends Model { + @attr name; + @belongsTo('person', { async: false, inverse: null }) + person; + } + + this.owner.register('model:person', Person); + this.owner.register('model:pet', Pet); + + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + + adapter.shouldBackgroundReloadRecord = () => false; + adapter.deleteRecord = () => { + return Promise.resolve({ data: null }); + }; + + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Chris Thoburn', + }, + relationships: { + pets: { + data: [ + { type: 'pet', id: '1' }, + { type: 'pet', id: '3' }, + ], + }, + }, + }, + included: [ + { + type: 'pet', id: '1', attributes: { - name: 'Chris Thoburn', - }, - relationships: { - pets: { - data: [ - { type: 'pet', id: '1' }, - { type: 'pet', id: '3' }, - ], - }, + name: 'Shenanigans', }, }, - included: [ - { - type: 'pet', - id: '1', - attributes: { - name: 'Shenanigans', - }, - }, - { - type: 'pet', - id: '2', - attributes: { - name: 'Rambunctious', - }, + { + type: 'pet', + id: '2', + attributes: { + name: 'Rambunctious', }, - { - type: 'pet', - id: '3', - attributes: { - name: 'Rebel', - }, + }, + { + type: 'pet', + id: '3', + attributes: { + name: 'Rebel', }, - ], - }); + }, + ], + }); - const person = store.peekRecord('person', '1'); - const pets = person.pets; + const person = store.peekRecord('person', '1'); + const pets = person.pets; - const shen = pets.at(0); - const rebel = store.peekRecord('pet', '3'); + const shen = pets.at(0); + const rebel = store.peekRecord('pet', '3'); - assert.strictEqual(shen.name, 'Shenanigans', 'precond - relationships work'); - assert.deepEqual( - pets.map((p) => p.id), - ['1', '3'], - 'precond - relationship has the correct pets to start' - ); + assert.strictEqual(shen.name, 'Shenanigans', 'precond - relationships work'); + assert.deepEqual( + pets.map((p) => p.id), + ['1', '3'], + 'precond - relationship has the correct pets to start' + ); - pets.splice(pets.indexOf(rebel), 1); + pets.splice(pets.indexOf(rebel), 1); - assert.deepEqual( - pets.map((p) => p.id), - ['1'], - 'precond2 - relationship now has the correct pet' - ); + assert.deepEqual( + pets.map((p) => p.id), + ['1'], + 'precond2 - relationship now has the correct pet' + ); - store.push({ - data: { - type: 'person', - id: '1', - relationships: { - pets: { - data: [ - { type: 'pet', id: '2' }, - { type: 'pet', id: '3' }, - ], - }, + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + pets: { + data: [ + { type: 'pet', id: '2' }, + { type: 'pet', id: '3' }, + ], }, }, - }); + }, + }); - const hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; + const hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; - assert.todo.deepEqual( - pets.map((p) => p.id), - ['2'], - 'relationship now has the correct current pets' - ); - assert.deepEqual( - hasManyCanonical.map((p) => p.id), - ['2', '3'], - 'relationship now has the correct canonical pets' - ); - } - ); + assert.deepEqual( + pets.map((p) => p.id), + ['2'], + 'relationship now has the correct current pets' + ); + assert.deepEqual( + hasManyCanonical.map((p) => p.id), + ['2', '3'], + 'relationship now has the correct canonical pets' + ); + }); test('new items added to an async hasMany relationship are not cleared by a delete', async function (assert) { assert.expect(7);