|
1 | 1 | import test from 'tape'
|
2 | 2 |
|
3 |
| -import {entryMock} from '../mocks' |
| 3 | +import {entryMock, assetMock} from '../mocks' |
4 | 4 | import {cloneDeep} from 'lodash/lang'
|
5 | 5 | import {wrapEntry, wrapEntryCollection} from '../../../lib/entities/entry'
|
6 | 6 |
|
@@ -30,12 +30,53 @@ test('Entry collection is wrapped', t => {
|
30 | 30 | limit: 100,
|
31 | 31 | items: [
|
32 | 32 | entryMock
|
| 33 | + ] |
| 34 | + } |
| 35 | + const wrappedEntry = wrapEntryCollection(entryCollection, true) |
| 36 | + t.looseEqual(wrappedEntry.toPlainObject(), entryCollection) |
| 37 | + t.end() |
| 38 | +}) |
| 39 | + |
| 40 | +test('Entry collection links are resolved', t => { |
| 41 | + const entryCollection = { |
| 42 | + total: 1, |
| 43 | + skip: 0, |
| 44 | + limit: 100, |
| 45 | + items: [ |
| 46 | + cloneDeep(entryMock), |
| 47 | + cloneDeep(entryMock) |
33 | 48 | ],
|
34 | 49 | includes: {
|
35 |
| - Entry: [] |
| 50 | + Asset: [ cloneDeep(assetMock) ] |
36 | 51 | }
|
37 | 52 | }
|
38 |
| - const wrappedEntry = wrapEntryCollection(entryCollection, true) |
39 |
| - t.looseEqual(wrappedEntry.toPlainObject(), entryCollection) |
| 53 | + // setup first entry |
| 54 | + entryCollection.items[0].sys.id = 'entry1' |
| 55 | + entryCollection.items[0].fields.linked1 = { |
| 56 | + sys: { |
| 57 | + id: 'asset1', |
| 58 | + type: 'Link', |
| 59 | + linkType: 'Asset' |
| 60 | + } |
| 61 | + } |
| 62 | + entryCollection.items[0].fields.linked2 = { |
| 63 | + sys: { |
| 64 | + id: 'entry3', |
| 65 | + type: 'Link', |
| 66 | + linkType: 'Entry' |
| 67 | + } |
| 68 | + } |
| 69 | + // setup first linked entry |
| 70 | + entryCollection.includes.Asset[0].sys.id = 'asset1' |
| 71 | + // setup second linked entry |
| 72 | + entryCollection.items[1].sys.id = 'entry3' |
| 73 | + |
| 74 | + const wrappedEntry = wrapEntryCollection(entryCollection, true).toPlainObject() |
| 75 | + // first linked entry resolved from includes |
| 76 | + t.equals(wrappedEntry.items[0].fields.linked1.sys.type, 'Asset', 'first linked entity is resolved') |
| 77 | + t.ok(wrappedEntry.items[0].fields.linked1.fields, 'first linked entity has fields') |
| 78 | + // second linked entry resolved from items list |
| 79 | + t.equals(wrappedEntry.items[0].fields.linked2.sys.type, 'Entry', 'second linked entity is resolved') |
| 80 | + t.ok(wrappedEntry.items[0].fields.linked2.fields, 'second linked entity has fields') |
40 | 81 | t.end()
|
41 | 82 | })
|
0 commit comments