|
| 1 | +import { Id } from '@graphprotocol/grc-20'; |
1 | 2 | import { describe, expect, it } from 'vitest'; |
2 | 3 |
|
3 | 4 | import { type Mapping, generateMapping, mapSchemaDataTypeToGRC20PropDataType } from '../src/Mapping.js'; |
@@ -76,6 +77,68 @@ describe('Mapping', () => { |
76 | 77 | }, |
77 | 78 | }; |
78 | 79 |
|
| 80 | + expect(actual).toEqual(expected); |
| 81 | + }); |
| 82 | + it('should use the existing KG ids if provided', async () => { |
| 83 | + const actual = await generateMapping({ |
| 84 | + types: [ |
| 85 | + { |
| 86 | + name: 'Account', |
| 87 | + knowledgeGraphId: 'a5fd07b1-120f-46c6-b46f-387ef98396a6', |
| 88 | + properties: [ |
| 89 | + { |
| 90 | + name: 'username', |
| 91 | + dataType: 'Text', |
| 92 | + knowledgeGraphId: '994edcff-6996-4a77-9797-a13e5e3efad8', |
| 93 | + }, |
| 94 | + { |
| 95 | + name: 'createdAt', |
| 96 | + dataType: 'Date', |
| 97 | + knowledgeGraphId: '64bfba51-a69b-4746-be4b-213214a879fe', |
| 98 | + }, |
| 99 | + ], |
| 100 | + }, |
| 101 | + { |
| 102 | + name: 'Event', |
| 103 | + knowledgeGraphId: null, |
| 104 | + properties: [ |
| 105 | + { |
| 106 | + name: 'name', |
| 107 | + dataType: 'Text', |
| 108 | + knowledgeGraphId: '3808e060-fb4a-4d08-8069-35b8c8a1902b', |
| 109 | + }, |
| 110 | + { |
| 111 | + name: 'description', |
| 112 | + dataType: 'Text', |
| 113 | + knowledgeGraphId: null, |
| 114 | + }, |
| 115 | + { |
| 116 | + name: 'speaker', |
| 117 | + dataType: 'Relation(Account)', |
| 118 | + knowledgeGraphId: null, |
| 119 | + }, |
| 120 | + ], |
| 121 | + }, |
| 122 | + ], |
| 123 | + }); |
| 124 | + const expected: Mapping = { |
| 125 | + Account: { |
| 126 | + typeIds: [Id.Id('a5fd07b1-120f-46c6-b46f-387ef98396a6')], |
| 127 | + properties: { |
| 128 | + username: Id.Id('994edcff-6996-4a77-9797-a13e5e3efad8'), |
| 129 | + createdAt: Id.Id('64bfba51-a69b-4746-be4b-213214a879fe'), |
| 130 | + }, |
| 131 | + }, |
| 132 | + Event: { |
| 133 | + typeIds: [expect.any(String)], |
| 134 | + properties: { |
| 135 | + name: Id.Id('3808e060-fb4a-4d08-8069-35b8c8a1902b'), |
| 136 | + description: expect.any(String), |
| 137 | + speaker: expect.any(String), |
| 138 | + }, |
| 139 | + }, |
| 140 | + }; |
| 141 | + |
79 | 142 | expect(actual).toEqual(expected); |
80 | 143 | }); |
81 | 144 | }); |
|
0 commit comments