Skip to content

Commit 61f65cd

Browse files
author
Tom Kirkpatrick
committed
Add some tests for fetching related data
1 parent 1fb38a8 commit 61f65cd

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
[{
22
"id": "1",
3-
"name": "Transaction 1",
3+
"name": "Transaction 1 (inv1)",
44
"storeId": "A",
55
"invoiceId": "1"
66
}, {
77
"id": "2",
8-
"name": "Transaction 2",
8+
"name": "Transaction 2 (inv1)",
99
"storeId": "A",
1010
"invoiceId": "1"
1111
}, {
1212
"id": "3",
13-
"name": "Transaction 3",
13+
"name": "Transaction 3 (inv2)",
1414
"storeId": "B",
1515
"invoiceId": "2"
1616
}, {
1717
"id": "4",
18-
"name": "Transaction 4",
18+
"name": "Transaction 4 (inv2)",
1919
"storeId": "B",
2020
"invoiceId": "2"
2121
}]

test/rest-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ describe('REST API', function() {
6464

6565
users.forEach(user => {
6666
describe(`${user.username} (User with ${user.abilities.join(', ')} permissions):`, function() {
67+
// related group content
68+
describe('related group content', function() {
69+
if (_includes(user.abilities, 'read')) {
70+
it('should fetch an invoices related transactions from the same team', function() {
71+
return logInAs(user.username)
72+
.then(res => json('get', `/api/invoices/1/transactions?access_token=${res.body.id}`)
73+
.expect(200))
74+
.then(res => {
75+
expect(res.body).to.be.an('array');
76+
expect(res.body).to.have.length(2);
77+
expect(res.body[0]).to.have.property('id', 1);
78+
expect(res.body[1]).to.have.property('id', 2);
79+
});
80+
});
81+
}
82+
it('should not fetch an invoice via a relationship from another teams transaction', function() {
83+
return logInAs(user.username)
84+
.then(res => json('get', `/api/transactions/3/invoice?access_token=${res.body.id}`)
85+
.expect(401));
86+
});
87+
});
88+
// end related group content
6789
// exists
6890
describe('exists', function() {
6991
if (_includes(user.abilities, 'read')) {

0 commit comments

Comments
 (0)