-
-
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.
- Loading branch information
1 parent
80bf8a5
commit 68544a2
Showing
6 changed files
with
176 additions
and
0 deletions.
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
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
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
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
10 changes: 10 additions & 0 deletions
10
tests/warp-drive__schema-record/tests/legacy/reads/relationships-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
83 changes: 83 additions & 0 deletions
83
tests/warp-drive__schema-record/tests/reads/belongs-to-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,83 @@ | ||
import type { TestContext } from '@ember/test-helpers'; | ||
|
||
import { module, test } from 'qunit'; | ||
|
||
import { setupTest } from 'ember-qunit'; | ||
|
||
import type Store from '@ember-data/store'; | ||
import type { Type } from '@warp-drive/core-types/symbols'; | ||
import { registerDerivations, withDefaults } from '@warp-drive/schema-record/schema'; | ||
|
||
type User = { | ||
id: string | null; | ||
$type: 'user'; | ||
name: string; | ||
bestFriend: User | null; | ||
[Type]: 'user'; | ||
}; | ||
|
||
module('Reads | belongsTo in linksMode', function (hooks) { | ||
setupTest(hooks); | ||
|
||
test('we can use sync belongsTo in linksMode', function (this: TestContext, assert) { | ||
const store = this.owner.lookup('service:store') as Store; | ||
const { schema } = store; | ||
|
||
registerDerivations(schema); | ||
|
||
schema.registerResource( | ||
withDefaults({ | ||
type: 'user', | ||
fields: [ | ||
{ | ||
name: 'name', | ||
kind: 'field', | ||
}, | ||
{ | ||
name: 'bestFriend', | ||
type: 'user', | ||
kind: 'belongsTo', | ||
options: { inverse: 'bestFriend', async: false, linksMode: true }, | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
const record = store.push<User>({ | ||
data: { | ||
type: 'user', | ||
id: '1', | ||
attributes: { | ||
name: 'Chris', | ||
}, | ||
relationships: { | ||
bestFriend: { | ||
data: { type: 'user', id: '2' }, | ||
}, | ||
}, | ||
}, | ||
included: [ | ||
{ | ||
type: 'user', | ||
id: '2', | ||
attributes: { | ||
name: 'Rey', | ||
}, | ||
relationships: { | ||
bestFriend: { | ||
data: { type: 'user', id: '1' }, | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
assert.strictEqual(record.id, '1', 'id is accessible'); | ||
assert.strictEqual(record.$type, 'user', '$type is accessible'); | ||
assert.strictEqual(record.name, 'Chris', 'name is accessible'); | ||
assert.strictEqual(record.bestFriend?.id, '2', 'bestFriend.id is accessible'); | ||
assert.strictEqual(record.bestFriend?.$type, 'user', 'bestFriend.user is accessible'); | ||
assert.strictEqual(record.bestFriend?.name, 'Rey', 'bestFriend.name is accessible'); | ||
assert.strictEqual(record.bestFriend?.bestFriend?.id, record.id, 'bestFriend is reciprocal'); | ||
}); | ||
}); |