|
| 1 | +import { expect, it } from 'vitest'; |
| 2 | +import { make } from './data.js'; |
| 3 | +import { SYSTEM_IDS } from '~/src/system-ids.js'; |
| 4 | + |
| 5 | +it('should generate ops for a data block entity', () => { |
| 6 | + const ops = make({ |
| 7 | + fromId: 'test-entity-id', |
| 8 | + sourceType: 'QUERY', |
| 9 | + position: 'test-position', |
| 10 | + }); |
| 11 | + |
| 12 | + const [blockTypeOp, blockSourceTypeOp, blockRelationOp] = ops; |
| 13 | + |
| 14 | + expect(blockTypeOp?.type).toBe('CREATE_RELATION'); |
| 15 | + if (blockTypeOp?.type === 'CREATE_RELATION') { |
| 16 | + expect(blockTypeOp?.relation.type).toBe(SYSTEM_IDS.TYPES_ATTRIBUTE); |
| 17 | + expect(blockTypeOp?.relation.toEntity).toBe(SYSTEM_IDS.DATA_BLOCK); |
| 18 | + } |
| 19 | + |
| 20 | + expect(blockSourceTypeOp?.type).toBe('CREATE_RELATION'); |
| 21 | + if (blockSourceTypeOp?.type === 'CREATE_RELATION') { |
| 22 | + expect(blockSourceTypeOp?.relation.type).toBe(SYSTEM_IDS.DATA_SOURCE_TYPE_RELATION_TYPE); |
| 23 | + expect(blockSourceTypeOp?.relation.toEntity).toBe(SYSTEM_IDS.QUERY_DATA_SOURCE); |
| 24 | + } |
| 25 | + |
| 26 | + expect(blockRelationOp?.type).toBe('CREATE_RELATION'); |
| 27 | + if (blockRelationOp?.type === 'CREATE_RELATION') { |
| 28 | + expect(blockRelationOp?.relation.type).toBe(SYSTEM_IDS.BLOCKS); |
| 29 | + expect(blockRelationOp?.relation.fromEntity).toBe('test-entity-id'); |
| 30 | + } |
| 31 | + |
| 32 | + expect(ops.length).toBe(3); |
| 33 | +}); |
| 34 | + |
| 35 | +it('should generate ops for a data block entity with a name', () => { |
| 36 | + const ops = make({ |
| 37 | + fromId: 'test-entity-id', |
| 38 | + sourceType: 'QUERY', |
| 39 | + position: 'test-position', |
| 40 | + name: 'test-name', |
| 41 | + }); |
| 42 | + |
| 43 | + const [blockTypeOp, blockSourceTypeOp, blockRelationOp, blockNameOp] = ops; |
| 44 | + |
| 45 | + expect(blockTypeOp?.type).toBe('CREATE_RELATION'); |
| 46 | + if (blockTypeOp?.type === 'CREATE_RELATION') { |
| 47 | + expect(blockTypeOp?.relation.type).toBe(SYSTEM_IDS.TYPES_ATTRIBUTE); |
| 48 | + expect(blockTypeOp?.relation.toEntity).toBe(SYSTEM_IDS.DATA_BLOCK); |
| 49 | + } |
| 50 | + |
| 51 | + expect(blockSourceTypeOp?.type).toBe('CREATE_RELATION'); |
| 52 | + if (blockSourceTypeOp?.type === 'CREATE_RELATION') { |
| 53 | + expect(blockSourceTypeOp?.relation.type).toBe(SYSTEM_IDS.DATA_SOURCE_TYPE_RELATION_TYPE); |
| 54 | + expect(blockSourceTypeOp?.relation.toEntity).toBe(SYSTEM_IDS.QUERY_DATA_SOURCE); |
| 55 | + } |
| 56 | + |
| 57 | + expect(blockRelationOp?.type).toBe('CREATE_RELATION'); |
| 58 | + if (blockRelationOp?.type === 'CREATE_RELATION') { |
| 59 | + expect(blockRelationOp?.relation.type).toBe(SYSTEM_IDS.BLOCKS); |
| 60 | + expect(blockRelationOp?.relation.fromEntity).toBe('test-entity-id'); |
| 61 | + } |
| 62 | + |
| 63 | + expect(blockNameOp?.type).toBe('SET_TRIPLE'); |
| 64 | + if (blockNameOp?.type === 'SET_TRIPLE') { |
| 65 | + expect(blockNameOp?.triple.attribute).toBe(SYSTEM_IDS.NAME_ATTRIBUTE); |
| 66 | + expect(blockNameOp?.triple.value.type).toBe('TEXT'); |
| 67 | + expect(blockNameOp?.triple.value.value).toBe('test-name'); |
| 68 | + } |
| 69 | +}); |
0 commit comments