unicloud-database.test.js 1.6 KB
Newer Older
雪洛's avatar
雪洛 已提交
1 2 3 4 5 6 7 8 9 10 11 12
const PAGE_PATH = '/pages/API/unicloud-database/unicloud-database'

describe('unicloud-database', () => {
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
  })
  it('databaseBasic', async () => {
    await page.callMethod('dbRemove')
    await page.waitFor(3000)
    await page.callMethod('dbAdd')
雪洛's avatar
雪洛 已提交
13
    await page.waitFor(2000)
雪洛's avatar
雪洛 已提交
14
    await page.callMethod('dbBatchAdd')
雪洛's avatar
雪洛 已提交
15
    await page.waitFor(2000)
雪洛's avatar
雪洛 已提交
16
    await page.callMethod('dbGet')
雪洛's avatar
雪洛 已提交
17
    await page.waitFor(2000)
雪洛's avatar
雪洛 已提交
18
    await page.callMethod('dbGetWithCommand')
雪洛's avatar
雪洛 已提交
19
    await page.waitFor(2000)
雪洛's avatar
雪洛 已提交
20
    await page.callMethod('dbUpdate')
雪洛's avatar
雪洛 已提交
21
    await page.waitFor(2000)
雪洛's avatar
雪洛 已提交
22
    await page.callMethod('dbRemove')
雪洛's avatar
雪洛 已提交
23
    await page.waitFor(2000)
雪洛's avatar
雪洛 已提交
24 25 26 27 28 29 30 31 32 33 34
    
    const {
      addId,
      batchAddIds,
      batchAddinserted,
      updateUpdated,
      getData,
      getWithCommandData,
      removeDeleted,
    } = await page.data()
    
雪洛's avatar
雪洛 已提交
35 36
    console.error((await page.data()).batchAddinserted)
    
雪洛's avatar
雪洛 已提交
37 38 39 40 41 42 43 44 45 46 47 48
    expect(addId.length > 0).toBe(true)
    expect(batchAddIds.length).toBe(2)
    expect(batchAddinserted).toBe(2)
    expect(getData.length).toBe(2)
    expect(getWithCommandData.length).toBe(2)
    expect(updateUpdated).toBe(3)
    expect(removeDeleted).toBe(3)
    
  })
  
  it('databaseLookup', async () => {
    await page.callMethod('dbLookupInit')
雪洛's avatar
雪洛 已提交
49
    await page.waitFor(3000)
雪洛's avatar
雪洛 已提交
50
    await page.callMethod('dbLookup')
雪洛's avatar
雪洛 已提交
51
    await page.waitFor(2000)
雪洛's avatar
雪洛 已提交
52 53 54 55 56 57 58 59 60
    
    const {
      lookupData
    } = await page.data()
    expect(lookupData.length).toBe(2)
    expect(lookupData[0]['foreign_id'].length).toBe(1)
    expect(lookupData[1]['foreign_id'].length).toBe(1)
  })
});