-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: make @id editable and reactive * fix lint
- Loading branch information
Showing
3 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
tests/warp-drive__schema-record/tests/legacy/create/basic-fields-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { module, test } from 'qunit'; | ||
|
||
import { setupTest } from 'ember-qunit'; | ||
|
||
import { | ||
registerDerivations as registerLegacyDerivations, | ||
withDefaults as withLegacy, | ||
} from '@ember-data/model/migration-support'; | ||
|
||
import type Store from 'warp-drive__schema-record/services/store'; | ||
|
||
interface User { | ||
id: string | null; | ||
$type: 'user'; | ||
name: string; | ||
age: number; | ||
netWorth: number; | ||
coolometer: number; | ||
rank: number; | ||
} | ||
|
||
module('Legacy | Create | basic fields', function (hooks) { | ||
setupTest(hooks); | ||
|
||
test('attributes work when passed to createRecord', function (assert) { | ||
const store = this.owner.lookup('service:store') as Store; | ||
const { schema } = store; | ||
registerLegacyDerivations(schema); | ||
|
||
schema.registerResource( | ||
withLegacy({ | ||
type: 'user', | ||
fields: [ | ||
{ | ||
name: 'name', | ||
type: null, | ||
kind: 'attribute', | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
const record = store.createRecord('user', { name: 'Rey Skybarker' }) as User; | ||
|
||
assert.strictEqual(record.id, null, 'id is accessible'); | ||
assert.strictEqual(record.name, 'Rey Skybarker', 'name is accessible'); | ||
}); | ||
|
||
test('id works when passed to createRecord', function (assert) { | ||
const store = this.owner.lookup('service:store') as Store; | ||
const { schema } = store; | ||
registerLegacyDerivations(schema); | ||
|
||
schema.registerResource( | ||
withLegacy({ | ||
type: 'user', | ||
fields: [ | ||
{ | ||
name: 'name', | ||
type: null, | ||
kind: 'attribute', | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
const record = store.createRecord('user', { id: '1' }) as User; | ||
|
||
assert.strictEqual(record.id, '1', 'id is accessible'); | ||
assert.strictEqual(record.name, undefined, 'name is accessible'); | ||
}); | ||
|
||
test('attributes work when updated after createRecord', function (assert) { | ||
const store = this.owner.lookup('service:store') as Store; | ||
const { schema } = store; | ||
registerLegacyDerivations(schema); | ||
|
||
schema.registerResource( | ||
withLegacy({ | ||
type: 'user', | ||
fields: [ | ||
{ | ||
name: 'name', | ||
type: null, | ||
kind: 'attribute', | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
const record = store.createRecord('user', {}) as User; | ||
assert.strictEqual(record.name, undefined, 'name is accessible'); | ||
record.name = 'Rey Skybarker'; | ||
assert.strictEqual(record.name, 'Rey Skybarker', 'name is accessible'); | ||
}); | ||
|
||
test('id works when updated after createRecord', function (assert) { | ||
const store = this.owner.lookup('service:store') as Store; | ||
const { schema } = store; | ||
registerLegacyDerivations(schema); | ||
|
||
schema.registerResource( | ||
withLegacy({ | ||
type: 'user', | ||
fields: [ | ||
{ | ||
name: 'name', | ||
type: null, | ||
kind: 'attribute', | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
const record = store.createRecord('user', {}) as User; | ||
assert.strictEqual(record.id, null, 'id is accessible'); | ||
record.id = '1'; | ||
assert.strictEqual(record.id, '1', 'id is accessible'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters