@@ -4,6 +4,12 @@ import { it, describe, beforeAll, afterAll, expect } from "vitest";
4
4
import { v4 as uuidv4 } from "uuid" ;
5
5
import { Neo4jContainer , StartedNeo4jContainer } from "@testcontainers/neo4j" ;
6
6
7
+ type Envelope = {
8
+ id : string ;
9
+ ontology : string ;
10
+ value : any ;
11
+ } ;
12
+
7
13
describe ( "DbService (integration)" , ( ) => {
8
14
let container : StartedNeo4jContainer ;
9
15
let service : DbService ;
@@ -28,42 +34,48 @@ describe("DbService (integration)", () => {
28
34
} ) ;
29
35
30
36
it ( "should store and retrieve a meta-envelope" , async ( ) => {
31
- const testId = uuidv4 ( ) ;
32
37
const input = {
33
- id : testId ,
34
38
ontology : "SocialMediaPost" ,
35
39
payload : {
36
40
text : "hello world" ,
37
41
dateCreated : "2025-04-10" ,
38
42
likes : [ "user1" , "user2" ] ,
39
43
} ,
44
+ acl : [ "@test-user" ] ,
40
45
} ;
41
46
42
- const result = await service . storeMetaEnvelope ( input , [ "@test-user" ] ) ;
47
+ const result = await service . storeMetaEnvelope ( input , input . acl ) ;
43
48
const id = result . metaEnvelope . id ;
44
49
45
50
const fetched = await service . findMetaEnvelopeById ( id ) ;
46
51
expect ( fetched ) . toBeDefined ( ) ;
47
52
expect ( fetched . id ) . toBeDefined ( ) ;
48
53
expect ( fetched . ontology ) . toBe ( "SocialMediaPost" ) ;
54
+ expect ( fetched . acl ) . toEqual ( [ "@test-user" ] ) ;
49
55
expect ( fetched . envelopes ) . toHaveLength ( 3 ) ;
56
+ expect ( fetched . envelopes [ 0 ] ) . toEqual (
57
+ expect . objectContaining ( {
58
+ id : expect . any ( String ) ,
59
+ ontology : expect . any ( String ) ,
60
+ value : expect . any ( String ) ,
61
+ } ) ,
62
+ ) ;
63
+
64
+ console . log ( fetched ) ;
50
65
} ) ;
51
66
52
67
it ( "should find meta-envelopes containing the search term in any envelope value" , async ( ) => {
53
- const metaId = uuidv4 ( ) ;
54
68
const input = {
55
- id : metaId ,
56
69
ontology : "SocialMediaPost" ,
57
70
payload : {
58
71
text : "This is a searchable tweet" ,
59
72
image : "https://example.com/image.jpg" ,
60
73
likes : [ "user1" , "user2" ] ,
61
74
} ,
75
+ acl : [ "@search-test-user" ] ,
62
76
} ;
63
77
64
- const metaEnv = await service . storeMetaEnvelope ( input , [
65
- "@search-test-user" ,
66
- ] ) ;
78
+ const metaEnv = await service . storeMetaEnvelope ( input , input . acl ) ;
67
79
68
80
const found = await service . findMetaEnvelopesBySearchTerm (
69
81
"SocialMediaPost" ,
@@ -97,52 +109,49 @@ describe("DbService (integration)", () => {
97
109
} ) ;
98
110
99
111
it ( "should delete a meta-envelope and its envelopes" , async ( ) => {
100
- const tempId = uuidv4 ( ) ;
101
112
const meta = {
102
- id : tempId ,
103
113
ontology : "TempPost" ,
104
114
payload : {
105
115
value : "to be deleted" ,
106
116
} ,
117
+ acl : [ "@delete-user" ] ,
107
118
} ;
108
119
109
- await service . storeMetaEnvelope ( meta , [ "@delete-user" ] ) ;
110
- await service . deleteMetaEnvelope ( tempId ) ;
120
+ const stored = await service . storeMetaEnvelope ( meta , meta . acl ) ;
121
+ await service . deleteMetaEnvelope ( stored . metaEnvelope . id ) ;
111
122
112
- const deleted = await service . findMetaEnvelopeById ( tempId ) ;
123
+ const deleted = await service . findMetaEnvelopeById (
124
+ stored . metaEnvelope . id ,
125
+ ) ;
113
126
expect ( deleted ) . toBeNull ( ) ;
114
127
} ) ;
115
128
116
129
it ( "should update envelope value" , async ( ) => {
117
- const testId = uuidv4 ( ) ;
118
130
const meta = {
119
- id : testId ,
120
131
ontology : "UpdateTest" ,
121
132
payload : {
122
133
value : "original" ,
123
134
} ,
135
+ acl : [ "@updater" ] ,
124
136
} ;
125
137
126
- const stored = await service . storeMetaEnvelope ( meta , [ "@updater" ] ) ;
138
+ const stored = await service . storeMetaEnvelope ( meta , meta . acl ) ;
127
139
128
140
const result = await service . findMetaEnvelopeById (
129
141
stored . metaEnvelope . id ,
130
142
) ;
131
143
const targetEnvelope = result . envelopes . find (
132
- ( e : any ) => e . properties . ontology === "value" ,
144
+ ( e : Envelope ) => e . ontology === "value" ,
133
145
) ;
134
146
135
- await service . updateEnvelopeValue (
136
- targetEnvelope . properties . id ,
137
- "updated" ,
138
- ) ;
147
+ await service . updateEnvelopeValue ( targetEnvelope . id , "updated" ) ;
139
148
140
149
const updated = await service . findMetaEnvelopeById (
141
150
stored . metaEnvelope . id ,
142
151
) ;
143
152
const updatedValue = updated . envelopes . find (
144
- ( e : any ) => e . properties . id === targetEnvelope . properties . id ,
153
+ ( e : Envelope ) => e . id === targetEnvelope . id ,
145
154
) ;
146
- expect ( updatedValue . properties . value ) . toBe ( "updated" ) ;
155
+ expect ( updatedValue . value ) . toBe ( "updated" ) ;
147
156
} ) ;
148
157
} ) ;
0 commit comments