-
Notifications
You must be signed in to change notification settings - Fork 0
/
test21_BulkDataOps.js
91 lines (77 loc) · 2.8 KB
/
test21_BulkDataOps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* LOWCODE-DATA-APP / copyright 2024 by ma-ha https://github.com/ma-ha / MIT License */
const assert = require( 'assert' )
const axios = require( 'axios' )
const helper = require( './helper' )
const API_URL = 'http://localhost:8888/app/adapter/entity/'
let HEADERS = {
'app-id' : 'mochatest',
'app-secret' : 'mochatest-supasecret-id'
}
describe( 'Data Ops Arr', () => {
let scopeId = null
let dtaUrl = ''
let testUuidUrl = ''
before( async () => {
scopeId = await helper.getRootScopeId()
assert.notEqual( scopeId, null )
testUuidUrl = API_URL + scopeId + '/mocha-test-app/1.0.0/testUUID'
// console.log( 'URL', dtaUrl )
})
// --------------------------------------------------------------------------
let uid = null
it( 'Add rec with auto id', async () => {
let rec = {
name : 'test3',
testRef : '2'
}
let result = await axios.post( testUuidUrl, rec, { headers: HEADERS } )
// console.log( result )
assert.equal( result.status, 200 )
// console.log( 'add one', result.data )
assert.notEqual( result.data.id, null )
uid = result.data.id
})
// --------------------------------------------------------------------------
let idArr = ['-']
it( 'Add rec array with auto id', async () => {
let recs = [
{ name : 't1', tag:'red', testRef : '2' },
{ name : 't2', tag:'red', testRef : '2' },
{ name : 't3', tag:'red', testRef : '2' },
{ name : 't4', tag:'blue', testRef : '2' },
{ name : 't5', tag:'blue', testRef : '2' },
]
let result = await axios.post( testUuidUrl, recs, { headers: HEADERS } )
// console.log( result )
assert.equal( result.status, 200 )
// console.log( 'add arr', result.data )
assert.notEqual( result.data.idArr, null )
assert.notEqual( result.data.docMap, null )
idArr = result.data.idArr
})
let docMap = {}
it( 'UUID: List data', async () => {
let result = await axios.get( testUuidUrl, { headers: HEADERS } )
assert.equal( result.status, 200 )
assert.notEqual( result.data, null )
assert.notEqual( result.data[ idArr[0] ], null )
assert.notEqual( result.data[ idArr[2] ], null )
assert.notEqual( result.data[ idArr[1] ], null )
// console.log( 'List result', result.data )
docMap = result.data
})
// --------------------------------------------------------------------------
it( 'Update rec array ', async () => {
let docArr = []
for ( let id in docMap ) {
docMap[ id ].addProp = 'blah'
docArr.push( docMap[ id ] )
}
// console.log( docArr )
let result = await axios.put( testUuidUrl, docArr, { headers: HEADERS } )
// console.log( result )
assert.equal( result.status, 200 )
// console.log( 'upd arr result', result.data )
assert.notEqual( result.data.docMap, null )
})
})