unicloud-database.test.js 1.7 KB
Newer Older
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
const PAGE_PATH = '/pages/API/unicloud-database/unicloud-database'
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isSafari = platformInfo.indexOf('safari') > -1

describe('unicloud-database', () => {
  if (isSafari) {
    it('web safari 暂时规避', () => {
      expect(1).toBe(1)
    })
    return
  }
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
    await page.setData({
      isUniTest: true
    })
  })
  it('databaseBasic', async () => {
    await page.callMethod('dbRemove')
    await page.callMethod('dbAdd')
    await page.callMethod('dbBatchAdd')
    await page.callMethod('dbGet')
    await page.callMethod('dbGetWithCommand')
    await page.callMethod('dbUpdate')
    await page.callMethod('dbRemove')
    await page.callMethod('dbMultiSend')

    const {
      addId,
      batchAddIds,
      batchAddinserted,
      updateUpdated,
      getData,
      getWithCommandData,
      removeDeleted,
      multiSendSuccessCount,
    } = await page.data()

    expect(addId !== '').toBe(true)
    expect(batchAddIds.length).toBe(2)
    expect(batchAddinserted).toBe(2)
    expect(getData.length).toBe(2)
    expect(getWithCommandData.length).toBe(1)
    expect(updateUpdated).toBe(3)
    expect(removeDeleted).toBe(3)
    expect(multiSendSuccessCount).toBe(2)

  })

  it('databaseLookup', async () => {
    await page.callMethod('dbLookupInit')
    await page.callMethod('dbLookup')

    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)
  })
});