From 77cbc38c158b153c19240eeab069daed49ba4994 Mon Sep 17 00:00:00 2001 From: yanglifeng Date: Tue, 29 Aug 2023 02:08:46 +0000 Subject: [PATCH] /RelationalStoreInsertJsunit.test.js. Signed-off-by: yanglifeng --- .../test/RelationalStoreInsertJsunit.test.js | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js index d3781cc01..6ec5d1959 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js @@ -1431,6 +1431,107 @@ describe('relationalStoreInsertTest', function () { console.log(TAG + " ************* InsertWithConflictResolution0007 end *************"); }) + + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0100 + * @tc.desc rdb insert test + */ + it('SUB_DDM_AppDataFWK_JSRDB_Insert_0100', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0100 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": null, + "salary": undefined, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket); + } + + { + const valueBucket = { + "id": 2, + "name": "lisi", + "age": 19, + "salary": 200.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket); + } + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + try { + done() + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("age"))); + expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("salary"))); + } catch (err) { + console.log("query error" + err); + expect().assertFail() + } + + { + const valueBucket = { + "age": null, + "salary": undefined, + } + predicates.equalTo("name", "lisi") + await rdbStore.update(valueBucket, predicates) + } + + predicates.clear(); + resultSet = await rdbStore.query(predicates); + try { + done(); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("age"))); + expect(200.5).assertEqual(resultSet.getDouble(resultSet.getColumnIndex("salary"))); + } catch (err) { + console.log("query error" + err); + expect().assertFail() + } + + resultSet.close() + resultSet = null + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0100 end *************"); + }) + + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0200 + * @tc.desc rdb insert test + */ + it('SUB_DDM_AppDataFWK_JSRDB_Insert_0200', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0200 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": new Date(), + "salary": 100.5, + "blobType": u8, + } + try { + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + done(); + expect().assertFail() + }).catch((err) => { + done(); + expect().assertFail() + }) + } catch (err) { + done(); + console.log("catch err: failed, err: code=" + err.code + " message=" + err.message) + expect('401').assertEqual(err.code) + } + } + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0200 end *************"); + }) console.info(TAG + " *************Unit Test End*************"); }) -- GitLab