|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { NAME_ATTRIBUTE } from '../core/ids/system.js'; |
| 3 | +import type { Op } from '../types.js'; |
| 4 | +import { createEntity } from './create-entity.js'; |
| 5 | +import { createRelationType } from './create-relation-type.js'; |
| 6 | +import { createType } from './create-type.js'; |
| 7 | + |
| 8 | +describe('Graph', () => { |
| 9 | + it('creates multiple types, relation types, entities, relations', async () => { |
| 10 | + const operations: Array<Op> = []; |
| 11 | + |
| 12 | + // create person type |
| 13 | + const { |
| 14 | + id: personTypeId, |
| 15 | + ops: createPersonTypeOps, |
| 16 | + mapping: personMapping, |
| 17 | + } = await createType({ |
| 18 | + attributes: { |
| 19 | + name: { |
| 20 | + id: NAME_ATTRIBUTE, |
| 21 | + type: 'TEXT', |
| 22 | + name: 'Name', |
| 23 | + }, |
| 24 | + age: { |
| 25 | + // ID is optional and will be generated automatically |
| 26 | + type: 'NUMBER', |
| 27 | + name: 'Age', |
| 28 | + }, |
| 29 | + }, |
| 30 | + }); |
| 31 | + operations.push(...createPersonTypeOps); |
| 32 | + |
| 33 | + // create restaurant type |
| 34 | + const { |
| 35 | + id: restaurantTypeId, |
| 36 | + ops: createRestaurantTypeOps, |
| 37 | + mapping: restaurantMapping, |
| 38 | + } = await createType({ |
| 39 | + attributes: { |
| 40 | + name: { |
| 41 | + id: NAME_ATTRIBUTE, |
| 42 | + type: 'TEXT', |
| 43 | + name: 'Name', |
| 44 | + }, |
| 45 | + }, |
| 46 | + }); |
| 47 | + operations.push(...createRestaurantTypeOps); |
| 48 | + |
| 49 | + // create loves relation type |
| 50 | + const { id: relationTypeId, ops: createRelationTypeOps } = await createRelationType({ |
| 51 | + from: personTypeId, |
| 52 | + to: restaurantTypeId, |
| 53 | + name: 'Loves', |
| 54 | + }); |
| 55 | + operations.push(...createRelationTypeOps); |
| 56 | + |
| 57 | + // create restaurant entity |
| 58 | + const { id: restaurantId, ops: createRestaurantOps } = await createEntity({ |
| 59 | + types: [restaurantTypeId], |
| 60 | + attributes: { |
| 61 | + name: 'Yummy Dining', |
| 62 | + }, |
| 63 | + mapping: restaurantMapping, |
| 64 | + }); |
| 65 | + operations.push(...createRestaurantOps); |
| 66 | + |
| 67 | + // create person entity |
| 68 | + const { id: personId, ops: createPersonOps } = await createEntity({ |
| 69 | + types: [personTypeId], |
| 70 | + attributes: { |
| 71 | + name: 'John Doe', |
| 72 | + }, |
| 73 | + mapping: personMapping, |
| 74 | + relations: [{ relationTypeId, toId: restaurantId }], |
| 75 | + }); |
| 76 | + operations.push(...createPersonOps); |
| 77 | + |
| 78 | + expect(operations.length).toBe(12); |
| 79 | + |
| 80 | + // publish all changes |
| 81 | + // const { proposalId } = await publish({ |
| 82 | + // operations, |
| 83 | + // editName: 'Create person, restaurant, and loves relation', |
| 84 | + // spaceId: '0x1', |
| 85 | + // accountId: '0x2', |
| 86 | + // }); |
| 87 | + }); |
| 88 | +}); |
0 commit comments