forked from salsify/ember-cli-pact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
people-qunit-test.js
54 lines (40 loc) · 1.84 KB
/
people-qunit-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { test, module } from 'qunit';
import { setupTest } from 'ember-qunit';
import { setupPact, given, interaction } from 'ember-cli-pact';
import { run } from '@ember/runloop';
module('Pact | People', function(hooks) {
setupTest(hooks);
setupPact(hooks);
test('listing people', async function(assert) {
given('a department exists', { id: '1', name: 'People' });
given('a person exists', { id: '1', name: 'Alice', departmentId: '1' });
given('a person exists', { id: '2', name: 'Bob', departmentId: '1' });
let people = await interaction(() => this.store().findAll('person'));
assert.deepEqual([...people.mapBy('id')], ['1', '2']);
assert.deepEqual([...people.mapBy('name')], ['Alice', 'Bob']);
assert.deepEqual([...people.mapBy('department.name')], ['People', 'People']);
});
test('querying people', async function(assert) {
given('a person exists', { id: '1', name: 'Alice' });
given('a person exists', { id: '2', name: 'Bob' });
let people = await interaction(() => this.store().query('person', { name: 'Bob' }));
assert.equal(people.get('length'), 1);
assert.equal(people.get('firstObject.id'), '2');
assert.equal(people.get('firstObject.name'), 'Bob');
});
test('fetching a person by ID', async function(assert) {
given('a person exists', { id: '1', name: 'Alice' });
let person = await interaction(() => this.store().findRecord('person', '1'));
assert.equal(person.get('id'), '1');
assert.equal(person.get('name'), 'Alice');
});
test('updating a person', async function(assert) {
given('a person exists', { id: '1', name: 'Alice' });
let person = await run(() => this.store().findRecord('person', '1'));
await interaction(() => {
person.set('name', 'Alicia');
return person.save();
});
assert.equal(person.get('name'), 'Alicia');
});
});