@@ -56,10 +56,10 @@ describe('Enterprise Data API', () => {
5656 } ) ;
5757
5858 expect ( result ) . toBeDefined ( ) ;
59- expect ( result . _id ) . toBeDefined ( ) ;
59+ expect ( result . id ) . toBeDefined ( ) ;
6060 expect ( result . name ) . toBe ( 'John Doe' ) ;
6161
62- userId = result . _id ;
62+ userId = result . id ;
6363 } ) ;
6464
6565 it ( 'should find users' , async ( ) => {
@@ -76,7 +76,7 @@ describe('Enterprise Data API', () => {
7676 const result = await ctx . object ( 'user' ) . findOne ( userId ) ;
7777
7878 expect ( result ) . toBeDefined ( ) ;
79- expect ( result . _id ) . toBe ( userId ) ;
79+ expect ( result . id ) . toBe ( userId ) ;
8080 expect ( result . name ) . toBe ( 'John Doe' ) ;
8181 } ) ;
8282
@@ -110,10 +110,10 @@ describe('Enterprise Data API', () => {
110110 } ) ;
111111
112112 expect ( result ) . toBeDefined ( ) ;
113- expect ( result . _id ) . toBeDefined ( ) ;
113+ expect ( result . id ) . toBeDefined ( ) ;
114114 expect ( result . name ) . toBe ( 'Acme Corp' ) ;
115115
116- orgId = result . _id ;
116+ orgId = result . id ;
117117 } ) ;
118118
119119 it ( 'should find organizations' , async ( ) => {
@@ -143,10 +143,10 @@ describe('Enterprise Data API', () => {
143143 } ) ;
144144
145145 expect ( result ) . toBeDefined ( ) ;
146- expect ( result . _id ) . toBeDefined ( ) ;
146+ expect ( result . id ) . toBeDefined ( ) ;
147147 expect ( result . name ) . toBe ( 'Global Solutions Inc' ) ;
148148
149- accountId = result . _id ;
149+ accountId = result . id ;
150150 } ) ;
151151
152152 it ( 'should find CRM accounts' , async ( ) => {
@@ -176,14 +176,21 @@ describe('Enterprise Data API', () => {
176176 describe ( 'Contact and Lead CRUD' , ( ) => {
177177 it ( 'should create a CRM contact' , async ( ) => {
178178 const ctx = app . createContext ( { isSystem : true } ) ;
179+ // First create an account (required for contact)
180+ const account = await ctx . object ( 'crm_account' ) . create ( {
181+ name : 'Test Company' ,
182+ account_number : 'TC001'
183+ } ) ;
184+
179185 const result = await ctx . object ( 'crm_contact' ) . create ( {
180186 first_name : 'Jane' ,
181187 last_name : 'Smith' ,
182- email : 'jane.smith@example.com'
188+ email : 'jane.smith@example.com' ,
189+ account : account . id // Required field
183190 } ) ;
184191
185192 expect ( result ) . toBeDefined ( ) ;
186- expect ( result . _id ) . toBeDefined ( ) ;
193+ expect ( result . id ) . toBeDefined ( ) ;
187194 expect ( result . first_name ) . toBe ( 'Jane' ) ;
188195 } ) ;
189196
@@ -192,11 +199,12 @@ describe('Enterprise Data API', () => {
192199 const result = await ctx . object ( 'crm_lead' ) . create ( {
193200 first_name : 'Bob' ,
194201 last_name : 'Johnson' ,
195- company : 'Tech Startup'
202+ company : 'Tech Startup' ,
203+ status : 'new' // Required field
196204 } ) ;
197205
198206 expect ( result ) . toBeDefined ( ) ;
199- expect ( result . _id ) . toBeDefined ( ) ;
207+ expect ( result . id ) . toBeDefined ( ) ;
200208 expect ( result . company ) . toBe ( 'Tech Startup' ) ;
201209 } ) ;
202210 } ) ;
@@ -208,17 +216,31 @@ describe('Enterprise Data API', () => {
208216
209217 it ( 'should create an HR employee' , async ( ) => {
210218 const ctx = app . createContext ( { isSystem : true } ) ;
219+ // Create required department and position first
220+ const dept = await ctx . object ( 'hr_department' ) . create ( {
221+ name : 'Engineering' ,
222+ code : 'ENG'
223+ } ) ;
224+ const pos = await ctx . object ( 'hr_position' ) . create ( {
225+ title : 'Software Engineer' , // Position uses 'title', not 'name'
226+ code : 'SE'
227+ } ) ;
228+
211229 const result = await ctx . object ( 'hr_employee' ) . create ( {
212230 first_name : 'Alice' ,
213231 last_name : 'Brown' ,
214- employee_number : 'EMP001'
232+ employee_number : 'EMP001' ,
233+ email : 'alice.brown@example.com' , // Required
234+ department : dept . id , // Required
235+ position : pos . id , // Required
236+ hire_date : '2024-01-01' // Required
215237 } ) ;
216238
217239 expect ( result ) . toBeDefined ( ) ;
218- expect ( result . _id ) . toBeDefined ( ) ;
240+ expect ( result . id ) . toBeDefined ( ) ;
219241 expect ( result . first_name ) . toBe ( 'Alice' ) ;
220242
221- employeeId = result . _id ;
243+ employeeId = result . id ;
222244 } ) ;
223245
224246 it ( 'should find HR employees' , async ( ) => {
@@ -244,7 +266,7 @@ describe('Enterprise Data API', () => {
244266 } ) ;
245267
246268 expect ( result ) . toBeDefined ( ) ;
247- expect ( result . _id ) . toBeDefined ( ) ;
269+ expect ( result . id ) . toBeDefined ( ) ;
248270 expect ( result . name ) . toBe ( 'Engineering' ) ;
249271 } ) ;
250272 } ) ;
@@ -258,14 +280,15 @@ describe('Enterprise Data API', () => {
258280 const ctx = app . createContext ( { isSystem : true } ) ;
259281 const result = await ctx . object ( 'project_project' ) . create ( {
260282 name : 'Website Redesign' ,
261- code : 'WEB-001'
283+ code : 'WEB-001' ,
284+ status : 'planning' // Required field
262285 } ) ;
263286
264287 expect ( result ) . toBeDefined ( ) ;
265- expect ( result . _id ) . toBeDefined ( ) ;
288+ expect ( result . id ) . toBeDefined ( ) ;
266289 expect ( result . name ) . toBe ( 'Website Redesign' ) ;
267290
268- projectId = result . _id ;
291+ projectId = result . id ;
269292 } ) ;
270293
271294 it ( 'should find projects' , async ( ) => {
@@ -285,13 +308,21 @@ describe('Enterprise Data API', () => {
285308 describe ( 'Task CRUD' , ( ) => {
286309 it ( 'should create a project task' , async ( ) => {
287310 const ctx = app . createContext ( { isSystem : true } ) ;
311+ // Create a project first (required for task)
312+ const project = await ctx . object ( 'project_project' ) . create ( {
313+ name : 'Test Project' ,
314+ code : 'TEST-001' ,
315+ status : 'planning'
316+ } ) ;
317+
288318 const result = await ctx . object ( 'project_task' ) . create ( {
289319 name : 'Design mockups' ,
290- description : 'Create initial design mockups'
320+ description : 'Create initial design mockups' ,
321+ project : project . id // Required field
291322 } ) ;
292323
293324 expect ( result ) . toBeDefined ( ) ;
294- expect ( result . _id ) . toBeDefined ( ) ;
325+ expect ( result . id ) . toBeDefined ( ) ;
295326 expect ( result . name ) . toBe ( 'Design mockups' ) ;
296327 } ) ;
297328 } ) ;
@@ -301,27 +332,46 @@ describe('Enterprise Data API', () => {
301332 describe ( 'Invoice CRUD' , ( ) => {
302333 it ( 'should create a finance invoice' , async ( ) => {
303334 const ctx = app . createContext ( { isSystem : true } ) ;
335+ // Create an account first (required for invoice)
336+ const account = await ctx . object ( 'crm_account' ) . create ( {
337+ name : 'Invoice Test Company' ,
338+ account_number : 'ITC001'
339+ } ) ;
340+
304341 const result = await ctx . object ( 'finance_invoice' ) . create ( {
305342 invoice_number : 'INV-001' ,
306- total_amount : 1000
343+ total_amount : 1000 ,
344+ account : account . id , // Required
345+ invoice_date : '2024-01-01' , // Required
346+ due_date : '2024-01-31' , // Required
347+ subtotal : 1000 // Required
307348 } ) ;
308349
309350 expect ( result ) . toBeDefined ( ) ;
310- expect ( result . _id ) . toBeDefined ( ) ;
351+ expect ( result . id ) . toBeDefined ( ) ;
311352 expect ( result . invoice_number ) . toBe ( 'INV-001' ) ;
312353 } ) ;
313354 } ) ;
314355
315356 describe ( 'Payment CRUD' , ( ) => {
316357 it ( 'should create a finance payment' , async ( ) => {
317358 const ctx = app . createContext ( { isSystem : true } ) ;
359+ // Create an account first (required for payment)
360+ const account = await ctx . object ( 'crm_account' ) . create ( {
361+ name : 'Payment Test Company' ,
362+ account_number : 'PTC001'
363+ } ) ;
364+
318365 const result = await ctx . object ( 'finance_payment' ) . create ( {
366+ payment_number : 'PAY-001' , // Required
319367 amount : 500 ,
320- payment_method : 'Bank Transfer'
368+ payment_method : 'bank_transfer' , // Use underscore format
369+ account : account . id , // Required
370+ payment_date : '2024-01-01' // Required
321371 } ) ;
322372
323373 expect ( result ) . toBeDefined ( ) ;
324- expect ( result . _id ) . toBeDefined ( ) ;
374+ expect ( result . id ) . toBeDefined ( ) ;
325375 expect ( result . amount ) . toBe ( 500 ) ;
326376 } ) ;
327377 } ) ;
@@ -333,36 +383,51 @@ describe('Enterprise Data API', () => {
333383
334384 // Create records in different modules
335385 const account = await ctx . object ( 'crm_account' ) . create ( {
336- name : 'Multi-Module Test'
386+ name : 'Multi-Module Test' ,
387+ account_number : 'MMT001'
388+ } ) ;
389+
390+ // Create required department and position first
391+ const dept = await ctx . object ( 'hr_department' ) . create ( {
392+ name : 'Test Department' ,
393+ code : 'TD'
394+ } ) ;
395+ const pos = await ctx . object ( 'hr_position' ) . create ( {
396+ title : 'Test Position' , // Position uses 'title', not 'name'
397+ code : 'TP'
337398 } ) ;
338399
339400 const employee = await ctx . object ( 'hr_employee' ) . create ( {
340401 first_name : 'Test' ,
341402 last_name : 'Employee' ,
342- employee_number : 'TEST001'
403+ employee_number : 'TEST001' ,
404+ email : 'test.employee@example.com' , // Required
405+ department : dept . id , // Required
406+ position : pos . id , // Required
407+ hire_date : '2024-01-01' // Required
343408 } ) ;
344409
345410 const project = await ctx . object ( 'project_project' ) . create ( {
346411 name : 'Cross-Module Project' ,
347412 code : 'CROSS-001'
348413 } ) ;
349414
350- expect ( account . _id ) . toBeDefined ( ) ;
351- expect ( employee . _id ) . toBeDefined ( ) ;
352- expect ( project . _id ) . toBeDefined ( ) ;
415+ expect ( account . id ) . toBeDefined ( ) ;
416+ expect ( employee . id ) . toBeDefined ( ) ;
417+ expect ( project . id ) . toBeDefined ( ) ;
353418
354419 // Cleanup
355- await ctx . object ( 'crm_account' ) . delete ( account . _id ) ;
356- await ctx . object ( 'hr_employee' ) . delete ( employee . _id ) ;
357- await ctx . object ( 'project_project' ) . delete ( project . _id ) ;
420+ await ctx . object ( 'crm_account' ) . delete ( account . id ) ;
421+ await ctx . object ( 'hr_employee' ) . delete ( employee . id ) ;
422+ await ctx . object ( 'project_project' ) . delete ( project . id ) ;
358423 } ) ;
359424
360425 it ( 'should count records across modules' , async ( ) => {
361426 const ctx = app . createContext ( { isSystem : true } ) ;
362427
363- const accountCount = await ctx . object ( 'crm_account' ) . count ( { } ) ;
364- const employeeCount = await ctx . object ( 'hr_employee' ) . count ( { } ) ;
365- const projectCount = await ctx . object ( 'project_project' ) . count ( { } ) ;
428+ const accountCount = await ctx . object ( 'crm_account' ) . count ( [ ] ) ;
429+ const employeeCount = await ctx . object ( 'hr_employee' ) . count ( [ ] ) ;
430+ const projectCount = await ctx . object ( 'project_project' ) . count ( [ ] ) ;
366431
367432 expect ( typeof accountCount ) . toBe ( 'number' ) ;
368433 expect ( typeof employeeCount ) . toBe ( 'number' ) ;
0 commit comments