Best JavaScript code snippet using storybook-root
AddAccount.test.js
Source:AddAccount.test.js
1/*2 * Copyright (c) 2021 Huawei Device Co., Ltd.3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15import account from '@ohos.account.appAccount'16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'17const NAMELIMIT = 512;18const LENGTHLIMIT = 1024;19describe('ActsAccountAddAccount', function () {20 /*21 * @tc.number : ActsAccountAddAccount_010022 * @tc.name : Add account calllback form23 * @tc.desc : Add account in calllback form without additional information24 */25 it('ActsAccountAddAccount_0100', 0, async function (done) {26 console.debug("====>ActsAccountAddAccount_0100 start====");27 var appAccountManager = account.createAppAccountManager();28 console.debug("====>creat finish====");29 appAccountManager.addAccount("account_name_callback_first", (err)=>{30 console.debug("====>add account ActsAccountAddAccount_0100 err:" + JSON.stringify(err));31 expect(err.code).assertEqual(0);32 appAccountManager.deleteAccount("account_name_callback_first", (err)=>{33 console.debug("====>delete Account ActsAccountAddAccount_0100 err:" + JSON.stringify(err));34 expect(err.code).assertEqual(0);35 console.debug("====>ActsAccountAddAccount_0100 end====");36 done();37 });38 });39 });40 /*41 * @tc.number : ActsAccountAddAccount_020042 * @tc.name : Add account promise form43 * @tc.desc : Add account in promise form without additional information44 */45 it('ActsAccountAddAccount_0200', 0, async function (done) {46 console.debug("====>ActsAccountAddAccount_0200 start====");47 var appAccountManager = account.createAppAccountManager();48 console.debug("====>creat finish====");49 console.debug("====>add account start====");50 try{51 await appAccountManager.addAccount("account_name_promise_first");52 }53 catch(err){54 console.error("====>add account fail err:" + JSON.stringify(err));55 expect().assertFail();56 done();57 }58 console.debug("====>delete account start====");59 await appAccountManager.deleteAccount("account_name_promise_first");60 console.debug("====>ActsAccountAddAccount_0200 end====");61 done(); 62 });63 /*64 * @tc.number : ActsAccountAddAccount_030065 * @tc.name : Add account calllback form66 * @tc.desc : Add account in calllback form with additional information67 */68 it('ActsAccountAddAccount_0300', 0, async function (done) {69 console.debug("====>ActsAccountAddAccount_0300 start====");70 var appAccountManager = account.createAppAccountManager();71 console.debug("====>creat finish====");72 appAccountManager.addAccount("account_name_callback_second", "account_extraInfo_callback_second", (err)=>{73 console.debug("====>add account ActsAccountAddAccount_0300 err:" + JSON.stringify(err));74 expect(err.code).assertEqual(0);75 appAccountManager.deleteAccount("account_name_callback_second", (err)=>{76 console.debug("====>delete Account ActsAccountAddAccount_0300 err:" + JSON.stringify(err));77 expect(err.code).assertEqual(0);78 console.debug("====>ActsAccountAddAccount_0300 end====");79 done();80 });81 });82 });83 /*84 * @tc.number : ActsAccountAddAccount_040085 * @tc.name : Add account promise form86 * @tc.desc : Add account in promise form with additional information87 */88 it('ActsAccountAddAccount_0400', 0, async function (done) {89 console.debug("====>ActsAccountAddAccount_0400 start====");90 var appAccountManager = account.createAppAccountManager();91 console.debug("====>creat finish====");92 console.debug("====>add account start====");93 try{94 await appAccountManager.addAccount("account_name_promise_second", "account_extraInfo_promise_second");95 }96 catch(err){97 console.error("====>add account fail err:" + JSON.stringify(err));98 expect().assertFail();99 done();100 }101 console.debug("====>delete account start====");102 await appAccountManager.deleteAccount("account_name_promise_second");103 console.debug("====>ActsAccountAddAccount_0400 end====");104 done();105 });106 /*107 * @tc.number : ActsAccountAddAccount_0500108 * @tc.name : Add account calllback form109 * @tc.desc : Repeatedly add the same name account and the same additional information110 */111 it('ActsAccountAddAccount_0500', 0, async function (done) {112 console.debug("====>ActsAccountAddAccount_0500 start====");113 var appAccountManager = account.createAppAccountManager();114 appAccountManager.addAccount("account_name_callback_third", "account_extraInfo_callback_third", (err)=>{115 console.debug("====>add account first time ActsAccountAddAccount_0500 err:" + JSON.stringify(err));116 expect(err.code).assertEqual(0);117 appAccountManager.addAccount("account_name_callback_third", "account_extraInfo_callback_third", (err)=>{118 console.debug("====>add account second time ActsAccountAddAccount_0500 err:" + JSON.stringify(err));119 expect(err.code != 0).assertEqual(true);120 appAccountManager.deleteAccount("account_name_callback_third", (err)=>{121 console.debug("====>delete Account ActsAccountAddAccount_0500 err:" + JSON.stringify(err));122 expect(err.code).assertEqual(0);123 console.debug("====>ActsAccountAddAccount_0500 end====");124 done();125 });126 });127 });128 });129 /*130 * @tc.number : ActsAccountAddAccount_0600131 * @tc.name : Add account promise form132 * @tc.desc : Repeatedly add the same name account and the same additional information133 */134 it('ActsAccountAddAccount_0600', 0, async function (done) {135 console.debug("====>ActsAccountAddAccount_0600 start====");136 var appAccountManager = account.createAppAccountManager();137 console.debug("====>add account for the first time ActsAccountAddAccount_0600====");138 await appAccountManager.addAccount("account_name_promise_third", "account_extraInfo_promise_third");139 console.debug("====>add account for the second time ActsAccountAddAccount_0600 start====");140 try{141 await appAccountManager.addAccount("account_name_promise_third", "account_extraInfo_promise_third");142 }143 catch(err){144 console.debug("====>add account for the second time 0600 err:" + JSON.stringify(err));145 expect(err.code != 0).assertEqual(true);146 await appAccountManager.deleteAccount("account_name_promise_third");147 console.debug("====>ActsAccountAddAccount_0600 end====");148 done();149 }150 });151 /*152 * @tc.number : ActsAccountAddAccount_0700153 * @tc.name : Add account calllback form154 * @tc.desc : The account name exceeds the length limit of 512 characters155 */156 it('ActsAccountAddAccount_0700', 0, async function (done) {157 console.debug("====>ActsAccountAddAccount_0700 start====");158 var limitAccountName = '';159 for (var i = 0; i < NAMELIMIT + 1; i++) {160 limitAccountName += 't';161 }162 var appAccountManager = account.createAppAccountManager();163 appAccountManager.addAccount(limitAccountName, "account_extraInfo_callback_fourth", (err)=>{164 console.debug("====>add account ActsAccountAddAccount_0700 err:" + JSON.stringify(err));165 expect(err.code != 0).assertEqual(true);166 console.debug("====>ActsAccountAddAccount_0700 end====");167 done();168 });169 });170 /*171 * @tc.number : ActsAccountAddAccount_0800172 * @tc.name : Add account promise form173 * @tc.desc : The account name exceeds the length limit of 512 characters174 */175 it('ActsAccountAddAccount_0800', 0, async function (done) {176 console.debug("====>ActsAccountAddAccount_0800 start====");177 var limitAccountName = '';178 for (var i = 0; i < NAMELIMIT + 1; i++) {179 limitAccountName += 'n';180 }181 var appAccountManager = account.createAppAccountManager();182 try{183 await appAccountManager.addAccount(limitAccountName, "account_extraInfo_promise_fourth");184 }185 catch(err){186 console.debug("====>add account ActsAccountAddAccount_0800 err:" + JSON.stringify(err));187 expect(err.code != 0).assertEqual(true);188 console.debug("====>ActsAccountAddAccount_0800 end====");189 done();190 }191 });192 /*193 * @tc.number : ActsAccountAddAccount_0900194 * @tc.name : Add account calllback form195 * @tc.desc : Additional information exceeds the length limit of 1024 characters196 */197 it('ActsAccountAddAccount_0900', 0, async function (done) {198 console.debug("====>ActsAccountAddAccount_0900 start====");199 var limitAccountExtra = '';200 for (var i = 0; i < LENGTHLIMIT + 1; i++) {201 limitAccountExtra += 't';202 }203 var appAccountManager = account.createAppAccountManager();204 appAccountManager.addAccount("account_name_callback_fifth", limitAccountExtra, (err)=>{205 console.debug("====>add account ActsAccountAddAccount_0900 err:" + JSON.stringify(err));206 expect(err.code != 0).assertEqual(true);207 console.debug("====>ActsAccountAddAccount_0900 end====");208 done();209 });210 });211 /*212 * @tc.number : ActsAccountAddAccount_1000213 * @tc.name : Add account promise form214 * @tc.desc : Additional information exceeds the length limit of 1024 characters215 */216 it('ActsAccountAddAccount_1000', 0, async function (done) {217 console.debug("====>ActsAccountAddAccount_1000 start====");218 var limitAccountExtra = '';219 for (var i = 0; i < LENGTHLIMIT + 1; i++) {220 limitAccountExtra += 'e';221 }222 var appAccountManager = account.createAppAccountManager();223 try{224 await appAccountManager.addAccount("account_name_promise_fifth", limitAccountExtra);225 }226 catch(err){227 console.debug("====>add account ActsAccountAddAccount_1000 err:" + JSON.stringify(err));228 expect(err.code != 0).assertEqual(true);229 console.debug("====>ActsAccountAddAccount_1000 end====");230 done();231 }232 });233 /*234 * @tc.number : ActsAccountAddAccount_1100235 * @tc.name : Add account calllback form236 * @tc.desc : The account name is an empty string237 */238 it('ActsAccountAddAccount_1100', 0, async function (done) {239 console.debug("====>ActsAccountAddAccount_1100 start====");240 var appAccountManager = account.createAppAccountManager();241 appAccountManager.addAccount("", "account_name_callback_sixth", (err)=>{242 console.debug("====>add account ActsAccountAddAccount_1100 err:" + JSON.stringify(err));243 expect(err.code != 0).assertEqual(true);244 console.debug("====>ActsAccountAddAccount_1100 end====");245 done();246 });247 });248 /*249 * @tc.number : ActsAccountAddAccount_1200250 * @tc.name : Add account promise form251 * @tc.desc : The account name is an empty string252 */253 it('ActsAccountAddAccount_1200', 0, async function (done) {254 console.debug("====>ActsAccountAddAccount_1200 start====");255 console.debug("====>ActsAccountAddAccount_1200 add account start====");256 var appAccountManager = account.createAppAccountManager();257 try{258 await appAccountManager.addAccount("", "account_name_promise_sixth");259 }260 catch(err){261 console.debug("====>add account ActsAccountAddAccount_1200 err:"+ JSON.stringify(err));262 expect(err.code != 0).assertEqual(true);263 console.debug("====>ActsAccountAddAccount_1200 end====");264 done();265 }266 });267 /*268 * @tc.number : ActsAccountAddAccount_1300269 * @tc.name : Add account calllback form270 * @tc.desc : Additional information is an empty string271 */272 it('ActsAccountAddAccount_1300', 0, async function (done) {273 console.debug("====>ActsAccountAddAccount_1300 start====");274 var appAccountManager = account.createAppAccountManager();275 appAccountManager.addAccount("account_name_callback_seventh", "", (err)=>{276 console.debug("====>add account ActsAccountAddAccount_1300 err:" + JSON.stringify(err));277 expect(err.code).assertEqual(0);278 appAccountManager.deleteAccount("account_name_callback_seventh", (err)=>{279 console.debug("====>delete Account ActsAccountAddAccount_1300 err:" + JSON.stringify(err));280 expect(err.code).assertEqual(0);281 console.debug("====>ActsAccountAddAccount_1300 end====");282 done();283 });284 });285 });286 /*287 * @tc.number : ActsAccountAddAccount_1400288 * @tc.name : Add account promise form289 * @tc.desc : Additional information is an empty string290 */291 it('ActsAccountAddAccount_1400', 0, async function (done) {292 console.debug("====>ActsAccountAddAccount_1400 start====");293 var appAccountManager = account.createAppAccountManager();294 console.debug("====>add account ActsAccountAddAccount_1400 start====");295 try{296 await appAccountManager.addAccount("account_name_promise_seventh", "");297 }298 catch(err){299 console.error("====>add account ActsAccountAddAccount_1400 err:" + JSON.stringify(err));300 expect().assertFail();301 done();302 }303 console.debug("====>delete account ActsAccountAddAccount_1400 start====");304 await appAccountManager.deleteAccount("account_name_promise_seventh");305 done();306 });307 /*308 * @tc.number : ActsAccountAddAccount_1500309 * @tc.name : Add account calllback form310 * @tc.desc : The account name is a special character such as a space311 */312 it('ActsAccountAddAccount_1500', 0, async function (done) {313 console.debug("====>ActsAccountAddAccount_1500 start====");314 var appAccountManager = account.createAppAccountManager();315 var specialStr = " ";316 appAccountManager.addAccount(specialStr, "account_extraInfo_callback_eight", (err)=>{317 console.debug("====>add account ActsAccountAddAccount_1500 err:" + JSON.stringify(err));318 expect(err.code != 0).assertEqual(true);319 console.debug("====>ActsAccountAddAccount_1500 end====");320 done();321 });322 });323 /*324 * @tc.number : ActsAccountAddAccount_1600325 * @tc.name : Add account promise form326 * @tc.desc : The account name is a special character such as a space327 */328 it('ActsAccountAddAccount_1600', 0, async function (done) {329 console.debug("====>ActsAccountAddAccount_1600 start====");330 var appAccountManager = account.createAppAccountManager();331 var specialStr = " ";332 try{333 await appAccountManager.addAccount(specialStr, "account_extraInfo_promise_eighth");334 }335 catch(err){336 console.debug("====>add Account ActsAccountAddAccount_1600 err:" + JSON.stringify(err));337 expect(err.code != 0).assertEqual(true);338 console.debug("====>ActsAccountAddAccount_1600 end====");339 done();340 }341 });342 /*343 * @tc.number : ActsAccountAddAccount_1700344 * @tc.name : Add account calllback form345 * @tc.desc : The account name is a special string346 */347 it('ActsAccountAddAccount_1700', 0, async function (done) {348 console.debug("====>ActsAccountAddAccount_1700 start====");349 var appAccountManager = account.createAppAccountManager();350 var specialStr = "#@$%^&*()_+!<>~?,./[]abcdefgABCDEFG1234567890";351 appAccountManager.addAccount(specialStr, "account_extraInfo_callback_ninth", (err)=>{352 console.debug("====>add account ActsAccountAddAccount_1700 err:" + JSON.stringify(err));353 expect(err.code).assertEqual(0);354 appAccountManager.deleteAccount(specialStr, (err)=>{355 console.debug("====>delete Account ActsAccountAddAccount_1700 err" + JSON.stringify(err));356 expect(err.code).assertEqual(0);357 console.debug("====>ActsAccountAddAccount_1700 end====");358 done();359 });360 });361 });362 /*363 * @tc.number : ActsAccountAddAccount_1800364 * @tc.name : Add account promise form365 * @tc.desc : The account name is a special string366 */367 it('ActsAccountAddAccount_1800', 0, async function (done) {368 console.debug("====>ActsAccountAddAccount_1800 start====");369 var appAccountManager = account.createAppAccountManager();370 var specialStr = "#@$%^&*()_+!<>~?,./[]abcdefgABCDEFG1234567890";371 console.debug("====>add account ActsAccountAddAccount_1800====");372 try{373 await appAccountManager.addAccount(specialStr, "account_extraInfo_promise_ninth");374 }375 catch(err){376 console.error("====>add Account ActsAccountAddAccount_1800 err:" + JSON.stringify(err));377 expect().assertFail();378 done();379 }380 console.debug("====>delete account ActsAccountAddAccount_1800====");381 await appAccountManager.deleteAccount(specialStr);382 console.debug("====>ActsAccountAddAccount_1800 end====");383 done();384 });385 /*386 * @tc.number : ActsAccountAddAccount_1900387 * @tc.name : Add account calllback form388 * @tc.desc : Additional information is a special character such as a space389 */390 it('ActsAccountAddAccount_1900', 0, async function (done) {391 console.debug("====>ActsAccountAddAccount_1900 start====");392 var appAccountManager = account.createAppAccountManager();393 var specialStr = " ";394 appAccountManager.addAccount("account_name_callback_tenth", specialStr, (err)=>{395 console.debug("====>add account ActsAccountAddAccount_1900 err:" + JSON.stringify(err));396 expect(err.code).assertEqual(0);397 appAccountManager.deleteAccount("account_name_callback_tenth", (err)=>{398 console.debug("====>delete Account ActsAccountAddAccount_1900 err" + JSON.stringify(err));399 expect(err.code).assertEqual(0);400 console.debug("====>ActsAccountAddAccount_1900 end====");401 done();402 });403 });404 });405 /*406 * @tc.number : ActsAccountAddAccount_2000407 * @tc.name : Add account promise form408 * @tc.desc : Additional information is a special character such as a space409 */410 it('ActsAccountAddAccount_2000', 0, async function (done) {411 console.debug("====>ActsAccountAddAccount_2000 start====");412 var appAccountManager = account.createAppAccountManager();413 var specialStr = " ";414 console.debug("====>add account ActsAccountAddAccount_2000====");415 try{416 await appAccountManager.addAccount("account_name_promise_tenth", specialStr);417 }418 catch(err){419 console.error("====>add Account ActsAccountAddAccount_2000 err:" + JSON.stringify(err));420 expect().assertFail();421 done();422 }423 console.debug("====>delete account ActsAccountAddAccount_2000====");424 await appAccountManager.deleteAccount("account_name_promise_tenth");425 console.debug("====>ActsAccountAddAccount_2000 end====");426 done();427 });428 /*429 * @tc.number : ActsAccountAddAccount_2100430 * @tc.name : Add account calllback form431 * @tc.desc : Additional information is a special string432 */433 it('ActsAccountAddAccount_2100', 0, async function (done) {434 console.debug("====>ActsAccountAddAccount_2100 start====");435 var appAccountManager = account.createAppAccountManager();436 var specialStr = "#@$%^&*()_+!<>~?,./[]abcdefgABCDEFG1234567890";437 appAccountManager.addAccount("account_extraInfo_callback_eleventh", specialStr, (err)=>{438 console.debug("====>add account ActsAccountAddAccount_2100 err:" + JSON.stringify(err));439 expect(err.code).assertEqual(0);440 appAccountManager.deleteAccount("account_extraInfo_callback_eleventh", (err)=>{441 console.debug("====>delete Account ActsAccountAddAccount_2100 err" + JSON.stringify(err));442 expect(err.code).assertEqual(0);443 console.debug("====>ActsAccountAddAccount_2100 end====");444 done();445 });446 });447 });448 /*449 * @tc.number : ActsAccountAddAccount_2200450 * @tc.name : Add account promise form451 * @tc.desc : Additional information is a special string452 */453 it('ActsAccountAddAccount_2200', 0, async function (done) {454 console.debug("====>ActsAccountAddAccount_2200 start====");455 var appAccountManager = account.createAppAccountManager();456 var specialStr = "#@$%^&*()_+!<>~?,./[]abcdefgABCDEFG1234567890";457 console.debug("====>add account ActsAccountAddAccount_2200====");458 try{459 await appAccountManager.addAccount("account_extraInfo_promise_eleventh", specialStr);460 }461 catch(err){462 console.error("====>add Account ActsAccountAddAccount_2200 err:" + JSON.stringify(err));463 expect().assertFail();464 done();465 }466 console.debug("====>delete account ActsAccountAddAccount_2200====");467 await appAccountManager.deleteAccount("account_extraInfo_promise_eleventh");468 console.debug("====>ActsAccountAddAccount_2200 end====");469 done();470 });471 /*472 * @tc.number : ActsAccountAddAccount_2300473 * @tc.name : Add account calllback form474 * @tc.desc : Repeatedly add accounts with the same name and different additional information475 */476 it('ActsAccountAddAccount_2300', 0, async function (done) {477 console.debug("====>ActsAccountAddAccount_2300 start====");478 var appAccountManager = account.createAppAccountManager();479 appAccountManager.addAccount("account_name_callback_same", "account_extraInfo_callback", (err)=>{480 console.debug("====>add account first time ActsAccountAddAccount_2300 err:" + JSON.stringify(err));481 expect(err.code).assertEqual(0);482 appAccountManager.addAccount("account_name_callback_same", "account_extraInfo_callback_different", (err)=>{483 console.debug("====>add account second time ActsAccountAddAccount_2300 err:" + JSON.stringify(err));484 expect(err.code != 0).assertEqual(true);485 appAccountManager.deleteAccount("account_name_callback_same", (err)=>{486 console.debug("====>delete Account ActsAccountAddAccount_2300 err:" + JSON.stringify(err));487 expect(err.code).assertEqual(0);488 console.debug("====>ActsAccountAddAccount_2300 end====");489 done();490 });491 });492 });493 });494 /*495 * @tc.number : ActsAccountAddAccount_2400496 * @tc.name : Add account promise form497 * @tc.desc : Repeatedly add accounts with the same name and different additional information498 */499 it('ActsAccountAddAccount_2400', 0, async function (done) {500 console.debug("====>ActsAccountAddAccount_2400 start====");501 var appAccountManager = account.createAppAccountManager();502 console.debug("====>add account for the first time ActsAccountAddAccount_2400====");503 await appAccountManager.addAccount("account_name_promise_same", "account_extraInfo_promise");504 console.debug("====>add account for the second time ActsAccountAddAccount_2400====");505 try{506 await appAccountManager.addAccount("account_name_promise_same", "account_extraInfo_promise_different");507 }508 catch(err){509 console.debug("====>add account for the second time err:" + JSON.stringify(err));510 expect(err.code != 0).assertEqual(true);511 appAccountManager.deleteAccount("account_name_promise_same"); 512 console.debug("====>ActsAccountAddAccount_2400 end====");513 done();514 }515 });516 /*517 * @tc.number : ActsAccountAddAccount_2500518 * @tc.name : Add account calllback form519 * @tc.desc : The account name reaches the limit of 512 characters520 */521 it('ActsAccountAddAccount_2500', 0, async function (done) {522 console.debug("====>ActsAccountAddAccount_2500 start====");523 var limitName = '';524 for (var i = 0; i < NAMELIMIT; i++) {525 limitName += 't';526 }527 var appAccountManager = account.createAppAccountManager();528 appAccountManager.addAccount(limitName, "account_extraInfo_callback", (err)=>{529 console.debug("====>add account ActsAccountAddAccount_2500 err:" + JSON.stringify(err));530 expect(err.code).assertEqual(0);531 appAccountManager.deleteAccount(limitName, (err)=>{532 console.debug("====>delete Account ActsAccountAddAccount_2500 err:" + JSON.stringify(err));533 expect(err.code).assertEqual(0);534 console.debug("====>ActsAccountAddAccount_2500 end====");535 done();536 });537 });538 });539 /*540 * @tc.number : ActsAccountAddAccount_2600541 * @tc.name : Add account promise form542 * @tc.desc : The account name reaches the limit of 512 characters543 */544 it('ActsAccountAddAccount_2600', 0, async function (done) {545 console.debug("====>ActsAccountAddAccount_2600 start====");546 var nameLimit = '';547 for (var i = 0; i < NAMELIMIT; i++) {548 nameLimit += 't';549 }550 var appAccountManager = account.createAppAccountManager();551 console.debug("====>add account ActsAccountAddAccount_2600 start====");552 try{553 await appAccountManager.addAccount(nameLimit, "account_extraInfo_promise");554 }555 catch(err){556 console.error("====>add account ActsAccountAddAccount_2600 err:" + JSON.stringify(err));557 expect().assertFail();558 done();559 }560 console.debug("====>delete account ActsAccountAddAccount_2600 start====");561 await appAccountManager.deleteAccount(nameLimit);562 console.debug("====>ActsAccountAddAccount_2600 end====");563 done();564 });565 /*566 * @tc.number : ActsAccountAddAccount_2700567 * @tc.name : Add account calllback form568 * @tc.desc : Additional information reaches the limit of 1024 characters569 */570 it('ActsAccountAddAccount_2700', 0, async function (done) {571 console.debug("====>ActsAccountAddAccount_2700 start====");572 var limitExtra = '';573 for (var i = 0; i < LENGTHLIMIT; i++) {574 limitExtra += 't';575 }576 var appAccountManager = account.createAppAccountManager();577 appAccountManager.addAccount("account_extra_callback_limit", limitExtra, (err)=>{578 console.debug("====>add account ActsAccountAddAccount_2700 err:" + JSON.stringify(err));579 expect(err.code).assertEqual(0);580 appAccountManager.deleteAccount("account_extra_callback_limit", (err)=>{581 console.debug("====>delete Account ActsAccountAddAccount_2700 err:" + JSON.stringify(err));582 expect(err.code).assertEqual(0);583 console.debug("====>ActsAccountAddAccount_2700 end====");584 done();585 });586 });587 });588 /*589 * @tc.number : ActsAccountAddAccount_2800590 * @tc.name : Add account promise form591 * @tc.desc : Additional information reaches the limit of 1024 characters592 */593 it('ActsAccountAddAccount_2800', 0, async function (done) {594 console.debug("====>ActsAccountAddAccount_2800 start====");595 var extraLimit = '';596 for (var i = 0; i < LENGTHLIMIT; i++) {597 extraLimit += 't';598 }599 var appAccountManager = account.createAppAccountManager();600 try{601 await appAccountManager.addAccount("account_extra_promise_limit", extraLimit);602 }603 catch(err){604 console.error("====>add account ActsAccountAddAccount_2800 err:" + JSON.stringify(err));605 expect().assertFail();606 done();607 }608 console.debug("====>delete account ActsAccountAddAccount_2800 start====");609 appAccountManager.deleteAccount("account_extra_promise_limit");610 console.debug("====>ActsAccountAddAccount_2800 end====");611 done();612 });...
DeleteAccount.test.js
Source:DeleteAccount.test.js
1/*2 * Copyright (c) 2021 Huawei Device Co., Ltd.3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15import account from '@ohos.account.appAccount'16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'17const TIMEOUT = 1000;18const STRCOUNT = 1025;19describe('ActsAccountDeleteAccount', function () {20 function sleep(delay) {21 var start = (new Date()).getTime();22 while((new Date()).getTime() - start < delay) {23 continue;24 }25 }26 beforeAll(async function (done) {27 console.debug("====>beforeAll start====");28 sleep(TIMEOUT);29 console.debug("====>beforeAll end====");30 done();31 });32 /*33 * @tc.number : ActsAccountDeleteAccount_010034 * @tc.name : Delete account calllback form35 * @tc.desc : Delete the added account in callback form36 */37 it('ActsAccountDeleteAccount_0100', 0, async function (done) {38 console.debug("====>ActsAccountDeleteAccount_0100 start====");39 var appAccountManager = account.createAppAccountManager();40 console.debug("====>creat finish====");41 appAccountManager.addAccount("deleteAccount_name_callback_first", "extraInfo_callback_first", (err)=>{42 console.debug("====>add account ActsAccountDeleteAccount_0100 err:" + JSON.stringify(err));43 expect(err.code).assertEqual(0);44 appAccountManager.deleteAccount("deleteAccount_name_callback_first", (err)=>{45 console.debug("====>delete Account ActsAccountDeleteAccount_0100 err:" + JSON.stringify(err));46 expect(err.code).assertEqual(0);47 console.debug("====>ActsAccountDeleteAccount_0100 end====");48 done();49 });50 });51 });52 /*53 * @tc.number : ActsAccountDeleteAccount_020054 * @tc.name : Delete account promise form55 * @tc.desc : Delete the added account in promise form56 */57 it('ActsAccountDeleteAccount_0200',0,async function (done){58 console.debug("====>ActsAccountDeleteAccount_0200 start====");59 var appAccountManager = account.createAppAccountManager();60 console.debug("====>add account ActsAccountAddAccount_0200 start====");61 await appAccountManager.addAccount("deleteAccount_name_promise_first","extraInfo_promise_first");62 try{63 await appAccountManager.deleteAccount("deleteAccount_name_promise_first");64 console.debug("====>ActsAccountDeleteAccount_0200 end====");65 done();66 }67 catch(err){68 console.error("====>delete account ActsAccountDeleteAccount_0200 err:" + JSON.stringify(err));69 expect().assertFail();70 done();71 }72 });73 /*74 * @tc.number : ActsAccountDeleteAccount_030075 * @tc.name : Delete account calllback form76 * @tc.desc : Delete unadded account in callback form77 */78 it('ActsAccountDeleteAccount_0300', 0, async function (done) {79 console.debug("====>ActsAccountDeleteAccount_0300 start====");80 var appAccountManager = account.createAppAccountManager();81 console.debug("====>creat finish====");82 appAccountManager.deleteAccount("deleteAccount_name_callback_second", (err)=>{83 console.debug("====>delete Account ActsAccountDeleteAccount_0300 err:" + JSON.stringify(err));84 expect(err.code != 0).assertEqual(true);85 console.debug("====>ActsAccountDeleteAccount_0300 end====");86 done();87 });88 });89 /*90 * @tc.number : ActsAccountDeleteAccount_040091 * @tc.name : Delete account promise form92 * @tc.desc : Delete unadded account in promise form93 */94 it('ActsAccountDeleteAccount_0400', 0, async function(done){95 console.debug("====>ActsAccountDeleteAccount_0400 start====");96 var appAccountManager = account.createAppAccountManager();97 try{98 await appAccountManager.deleteAccount("deleteAccount_name_promise_second");99 }100 catch(err){101 console.debug("====>delete account ActsAccountDeleteAccount_0400 err:" + JSON.stringify(err));102 expect(err.code != 0).assertEqual(true);103 console.debug("====>ActsAccountDeleteAccount_0400 end====");104 done();105 }106 });107 /*108 * @tc.number : ActsAccountDeleteAccount_0500109 * @tc.name : Delete account calllback form110 * @tc.desc : Delete the added account, the first time it can be deleted, the second time the deletion fails111 */112 it('ActsAccountDeleteAccount_0500', 0, async function (done) {113 console.debug("====>ActsAccountDeleteAccount_0500 start====");114 var appAccountManager = account.createAppAccountManager();115 appAccountManager.addAccount("deleteAccount_name_callback_third", "extraInfo_callback_third", (err)=>{116 console.debug("====>add account ActsAccountDeleteAccount_0500 err:" + JSON.stringify(err));117 expect(err.code).assertEqual(0);118 appAccountManager.deleteAccount("deleteAccount_name_callback_third", (err)=>{119 console.debug("====>delete account first time err:" + JSON.stringify(err));120 expect(err.code).assertEqual(0);121 appAccountManager.deleteAccount("deleteAccount_name_callback_third", (err)=>{122 console.debug("====>delete Account second time err:" + JSON.stringify(err));123 expect(err.code != 0).assertEqual(true);124 console.debug("====>ActsAccountDeleteAccount_0500 end====");125 done();126 });127 });128 });129 });130 /*131 * @tc.number : ActsAccountDeleteAccount_0600132 * @tc.name : Delete account promise form133 * @tc.desc : Delete the added account, the first time it can be deleted, the second time the deletion fails134 */135 it('ActsAccountDeleteAccount_0600', 0, async function (done){136 console.debug("====>ActsAccountDeleteAccount_0600 start====");137 var appAccountManager = account.createAppAccountManager();138 console.debug("====>add account ActsAccountAddAccount_0600 start====");139 await appAccountManager.addAccount("deleteAccount_name_promise_third", "extraInfo_promise_third");140 console.debug("====>delete Account first time ActsAccountDeleteAccount_0600 start====");141 await appAccountManager.deleteAccount("deleteAccount_name_promise_third");142 console.debug("====>delete Account second time ActsAccountDeleteAccount_0600 start====");143 try{144 await appAccountManager.deleteAccount("deleteAccount_name_promise_third");145 }146 catch(err){147 console.debug("====>delete account ActsAccountDeleteAccount_0600 err:" + JSON.stringify(err));148 expect(err.code != 0).assertEqual(true);149 console.debug("====>ActsAccountDeleteAccount_0600 end====");150 done();151 }152 });153 /*154 * @tc.number : ActsAccountDeleteAccount_0700155 * @tc.name : Delete account calllback form156 * @tc.desc : Delete the account name exceeds the length limit of 1024157 */158 it('ActsAccountDeleteAccount_0700',0, async function (done){159 console.debug("====>ActsAccountDeleteAccount_0700 start====");160 var bigStr = '';161 for (var i = 0; i < STRCOUNT; i++) {162 bigStr += 't';163 }164 var appAccountManager = account.createAppAccountManager();165 appAccountManager.deleteAccount(bigStr, (err)=>{166 console.debug("====>delete Account ActsAccountDeleteAccount_0700 err:" + JSON.stringify(err));167 expect(err.code != 0).assertEqual(true);168 console.debug("====>ActsAccountDeleteAccount_0700 end====");169 done();170 });171 });172 /*173 * @tc.number : ActsAccountDeleteAccount_0800174 * @tc.name : Delete account promise form175 * @tc.desc : Delete the account name exceeds the length limit of 1024176 */177 it('ActsAccountDeleteAccount_0800', 0, async function (done){178 console.debug("====>ActsAccountDeleteAccount_0800 start====");179 var bigStr = '';180 for (var i = 0; i < STRCOUNT; i++) {181 bigStr += 't';182 }183 var appAccountManager = account.createAppAccountManager();184 console.debug("====>delete Account ActsAccountDeleteAccount_0800 start====");185 try{186 await appAccountManager.deleteAccount(bigStr);187 }188 catch(err){189 console.debug("====>delete account ActsAccountDeleteAccount_0800 err:" + JSON.stringify(err));190 expect(err.code != 0).assertEqual(true);191 console.debug("====>ActsAccountDeleteAccount_0800 end====");192 done();193 }194 })195 /*196 * @tc.number : ActsAccountDeleteAccount_0900197 * @tc.name : Delete account calllback form198 * @tc.desc : Delete the account name is an empty string199 */200 it('ActsAccountDeleteAccount_0900',0, async function (done){201 console.debug("====>ActsAccountDeleteAccount_0900 start====");202 var appAccountManager = account.createAppAccountManager();203 appAccountManager.deleteAccount("", (err)=>{204 console.debug("====>delete Account ActsAccountDeleteAccount_0900 err:" + JSON.stringify(err));205 expect(err.code != 0).assertEqual(true);206 console.debug("====>ActsAccountDeleteAccount_0900 end====");207 done();208 });209 });210 /*211 * @tc.number : ActsAccountDeleteAccount_1000212 * @tc.name : Delete account promise form213 * @tc.desc : Delete the account name is an empty string214 */215 it('ActsAccountDeleteAccount_1000', 0, async function (done){216 console.debug("====>ActsAccountDeleteAccount_1000 start====");217 var appAccountManager = account.createAppAccountManager();218 console.debug("====>delete Account ActsAccountDeleteAccount_1000 start====");219 try{220 await appAccountManager.deleteAccount("");221 }222 catch(err){223 console.debug("====>delete account ActsAccountDeleteAccount_1000 err:" + JSON.stringify(err));224 expect(err.code != 0).assertEqual(true);225 console.debug("====>ActsAccountDeleteAccount_1000 end====");226 done();227 }228 })...
account.service.spec.ts
Source:account.service.spec.ts
1import { Account } from '../src/database/entities/account.entity';2import { AccountService } from '../src/services/account.service';3import { Repository, getCustomRepository } from 'typeorm';4import { IAccount } from '../src/interfaces/account.interface';5import { Generator } from '../src/helpers/generator';6jest.mock('../src/helpers/generator', () => ({7 Generator: {8 generateAccountNumber: jest.fn().mockImplementation(() => Math.round(Math.random() * 10000000000) + "")9 }10}))11describe('AccountService', () => {12 let accountsDB = [] as IAccount[];13 let accountRepository;14 let accountService: AccountService;15 beforeEach(async () => {16 accountRepository = {17 findOne: ({ accountNumber }) => {18 return accountsDB.find(account => account.accountNumber == accountNumber);19 },20 save: (account: IAccount) => {21 const index = accountsDB.map(account => account.accountNumber).indexOf(account.accountNumber);22 if (index == -1) {23 account.id = accountsDB.length + 1;24 account.balance = account.balance ? 0 : account.balance;25 accountsDB.push(account);26 return account;27 } else {28 accountsDB[index] = account;29 return account;30 }31 },32 };33 // console.log(accountRepository);34 accountService = new AccountService(accountRepository);35 });36 afterEach(() => {37 accountsDB = [];38 })39 //createAccount40 it('should throw and exception if name is not set', async () => {41 try {42 await accountService.createAccount({} as IAccount);43 } catch (e) {44 expect(e.message).toBe('Name is required');45 }46 });47 it('should create an account', async () => {48 const validAccount = { name: "john doe" } as IAccount;49 const createdAccount = await accountService.createAccount(validAccount);50 console.log('createdAccount', createdAccount);51 expect(validAccount.name).toBe(createdAccount.name);52 expect(createdAccount.accountNumber).toBeDefined()53 expect(createdAccount.id).toBeDefined()54 });55 //fundAccount56 it('should throw an exception if amount is less than 0', async () => {57 const testAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 0 } as IAccount;58 accountsDB.push(testAccount);59 const accountNumber = '9854743932'60 try {61 await accountService.fundAccount(accountNumber, -2);62 } catch (e) {63 expect(e.message).toBe('Invalid fund amount');64 }65 });66 it('should throw an exception if account is not found', async () => {67 const testAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 0 } as IAccount;68 accountsDB.push(testAccount);69 const accountNumber = '9854743933'70 try {71 const createdAccount = await accountService.fundAccount(accountNumber, 200);72 } catch (e) {73 expect(e.message).toBe('Invalid Account number');74 }75 });76 it('should add to account balance', async () => {77 const testAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 0 } as IAccount;78 accountsDB.push(testAccount);79 const accountNumber = '9854743932'80 const createdAccount = await accountService.fundAccount(accountNumber, 200);81 expect(createdAccount.balance).toBe(200);82 });83 //transferToAnother84 it('should throw an exception if amount is less than 0', async () => {85 const sourceAccountNumber = '9854743932'86 const destinationAccountNo = '2854743932'87 try {88 await accountService.transferToAnother(sourceAccountNumber, destinationAccountNo, -200);89 } catch (e) {90 expect(e.message).toBe('Invalid fund amount');91 }92 });93 it('should throw an exception if source account number is the same as destination account number', async () => {94 const sourceAccountNumber = '9854743932'95 const destinationAccountNo = '9854743932'96 try {97 await accountService.transferToAnother(sourceAccountNumber, destinationAccountNo, 200);98 } catch (e) {99 expect(e.message).toBe('Source account number can not be the same as destination account number');100 }101 });102 it('should throw an exception if source account is not found', async () => {103 const sourceAccountNumber = '9854743932'104 const destinationAccountNo = '2854743932'105 try {106 await accountService.transferToAnother(sourceAccountNumber, destinationAccountNo, 200);107 } catch (e) {108 expect(e.message).toBe('Invalid Source Account number');109 }110 });111 it('should throw an exception if destination account is not found', async () => {112 const sourceAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 0 } as IAccount;113 accountsDB.push(sourceAccount);114 const destinationAccountNo = '2854743932'115 try {116 await accountService.transferToAnother(sourceAccount.accountNumber, destinationAccountNo, 200);117 } catch (e) {118 expect(e.message).toBe('Invalid Destination Account number');119 }120 });121 it('should throw an exception if source account balance is less than transfer amount', async () => {122 const sourceAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 0 } as IAccount;123 const destinationAccount = { name: 'john doe', accountNumber: '2854743932', id: 1, balance: 0 } as IAccount;124 accountsDB.push(sourceAccount, destinationAccount);125 try {126 await accountService.transferToAnother(sourceAccount.accountNumber, destinationAccount.accountNumber, 200);127 } catch (e) {128 expect(e.message).toBe('Insufficient funds');129 }130 });131 it('should transfer to destination account', async () => {132 const sourceAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 500 } as IAccount;133 const destinationAccount = { name: 'john doe', accountNumber: '4854743932', id: 1, balance: 0 } as IAccount;134 accountsDB.push(sourceAccount, destinationAccount);135 const newSourceAccount = await accountService.transferToAnother(sourceAccount.accountNumber, destinationAccount.accountNumber, 200);136 const newDestinationAccount = await accountService.findOne(destinationAccount.accountNumber);137 expect(newSourceAccount.balance).toBe(300);138 expect(newDestinationAccount.balance).toBe(200)139 });140 //withdraw141 it('should throw an exception if amount is less than 0', async () => {142 const sourceAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 0 } as IAccount;143 accountsDB.push(sourceAccount);144 try {145 await accountService.withdraw(sourceAccount.accountNumber, -200);146 } catch (e) {147 expect(e.message).toBe('Invalid fund amount');148 }149 });150 it('should throw an exception if account is not found', async () => {151 try {152 await accountService.withdraw('9854743932', 200);153 } catch (e) {154 expect(e.message).toBe('Invalid Account number');155 }156 });157 it('should throw an exception if account balance is less than transfer amount', async () => {158 const sourceAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 0 } as IAccount;159 accountsDB.push(sourceAccount);160 try {161 await accountService.withdraw(sourceAccount.accountNumber, 200);162 } catch (e) {163 expect(e.message).toBe('Insufficient funds');164 }165 });166 it('should be able to withdraw amount', async () => {167 const sourceAccount = { name: 'john doe', accountNumber: '9854743932', id: 1, balance: 500000 } as IAccount;168 accountsDB.push(sourceAccount);169 const newAccount = await accountService.withdraw(sourceAccount.accountNumber, 200);170 expect(newAccount.balance).toBe(500000 - 200);171 });...
account.component.ts
Source:account.component.ts
1import { Component, OnInit, Inject } from '@angular/core';2import { AccountService } from 'src/app/services/account.service';3import { Account } from 'src/app/element/account';4import { VirtualAccount } from 'src/app/element/virtualaccount';5import { LoggerService } from 'src/app/services/logger.service';6import {7 MatDialog,8 MatDialogRef,9 MAT_DIALOG_DATA,10} from '@angular/material/dialog';11import { AccountType } from 'src/app/element/accounttype';12import { AccountTypeService } from 'src/app/services/accounttype.service';13import { VirtualAccountService } from 'src/app/services/virtualaccount.service';14import { Observable, BehaviorSubject } from 'rxjs';15import { switchMap } from 'rxjs/operators';16import { Router } from '@angular/router';17export interface AccountDialogData {18 account: Account;19 accountTypes: Observable<AccountType[]>;20 isNew: boolean;21}22export interface VirtualAccountDialogData {23 virtualAccount: VirtualAccount;24 new: boolean;25}26@Component({27 selector: 'app-account',28 templateUrl: './account.component.html',29 styleUrls: ['./account.component.css'],30})31export class AccountComponent implements OnInit {32 displayedColumns: string[] = ['name', 'edit'];33 opened: boolean;34 private readonly refreshToken$ = new BehaviorSubject(undefined);35 readonly accounts = this.refreshToken$.pipe(36 switchMap(() => this.accountService.getAccounts())37 );38 constructor(39 private accountService: AccountService,40 private accountTypeService: AccountTypeService,41 private virtualAccountService: VirtualAccountService,42 private logger: LoggerService,43 public dialog: MatDialog,44 private route: Router45 ) {}46 ngOnInit(): void {}47 selectAccount(account: Account) {48 this.route.navigate(['/realAccount/transactions', { id: account.id }]);49 }50 selectVirtualAccount(account: VirtualAccount) {51 this.route.navigate(['/virtualAccount/transactions', { id: account.id }]);52 }53 deleteAccount(account: Account) {54 this.logger.log(account, 'AccountComponent');55 // TODO delete and reload56 }57 editAccount(editedAccount: Account): void {58 let account: Account;59 if (editedAccount === null) {60 account = {61 id: null,62 name: null,63 accountType: null,64 };65 } else {66 account = editedAccount;67 }68 const isNew = editedAccount === null;69 const accountTypes = this.accountTypeService.getAccountTypes();70 const accountDialog = this.dialog.open(AccountCreationDialogComponent, {71 data: { account, accountTypes, isNew },72 });73 accountDialog.afterClosed().subscribe((result) => {74 if (result !== undefined) {75 if (editedAccount === null) {76 this.accountService77 .addAccount(result.account)78 .subscribe(() => this.refreshToken$.next(undefined));79 } else {80 this.accountService81 .updateAccount(result.account)82 .subscribe(() => this.refreshToken$.next(undefined));83 }84 } else {85 this.refreshToken$.next(undefined);86 }87 });88 }89 deleteVirtualAccount(account: VirtualAccount) {90 this.logger.log(account, 'AccountComponent');91 // TODO delete and reload92 }93 editVirtualAccount(editedAccount: VirtualAccount, account: Account): void {94 let virtualAccount: VirtualAccount;95 if (editedAccount === null) {96 virtualAccount = {97 id: null,98 name: null,99 underlyingAccount: account,100 };101 } else {102 virtualAccount = editedAccount;103 }104 const virtualAccountDialog = this.dialog.open(105 VirtualAccountCreationDialogComponent,106 {107 data: { virtualAccount },108 }109 );110 virtualAccountDialog.afterClosed().subscribe((result) => {111 if (result !== undefined) {112 if (editedAccount === null) {113 this.virtualAccountService114 .addVirtualAccount(result.virtualAccount)115 .subscribe(() => this.refreshToken$.next(undefined));116 } else {117 this.virtualAccountService118 .updateVirtualAccount(result.virtualAccount)119 .subscribe(() => this.refreshToken$.next(undefined));120 }121 } else {122 this.refreshToken$.next(undefined);123 }124 });125 }126}127@Component({128 selector: 'app-account-creation-dialog',129 templateUrl: 'account-creation-dialog.html',130 styleUrls: ['./account.component.css'],131})132export class AccountCreationDialogComponent {133 constructor(134 public accountDialog: MatDialogRef<AccountCreationDialogComponent>,135 @Inject(MAT_DIALOG_DATA) public data: AccountDialogData136 ) {}137 onNoClick(): void {138 this.accountDialog.close();139 }140 isDisabled(account: Account): boolean {141 let active = true;142 active = active && account.name !== null;143 active = active && account.accountType !== null;144 return !active;145 }146 compareType(value1: AccountType, value2: AccountType) {147 if (value1 !== null && value2 !== null) {148 return value1.value === value2.value;149 }150 }151}152@Component({153 selector: 'app-account-creation-dialog',154 templateUrl: 'virtual-account-creation-dialog.html',155 styleUrls: ['./account.component.css'],156})157export class VirtualAccountCreationDialogComponent {158 constructor(159 public virtualAccountDialog: MatDialogRef<VirtualAccountCreationDialogComponent>,160 @Inject(MAT_DIALOG_DATA) public data: VirtualAccountDialogData161 ) {}162 onNoClick(): void {163 this.virtualAccountDialog.close();164 }165 isDisabled(virtualAccount: VirtualAccount): boolean {166 let active = true;167 active = active && virtualAccount.name !== null;168 return !active;169 }...
account-repository.ts
Source:account-repository.ts
1import { AddAccountRepository } from '@/data/protocols/db/account/add-account-repository'2import { FindAccountByIdRepository } from '@/data/protocols/db/account/find-account-by-id-repository'3import { RemoveAccountRepository } from '@/data/protocols/db/account/remove-account-repository'4import { UpdateAccountRepository } from '@/data/protocols/db/account/update-account-repository'5import { AccountModel, AccountModelResponse, FindAccountByEmailRepository } from '@/data/usecases/authentication/db-authentication-protocols'6import { AddAccountParams } from '@/domain/usecases/account/add-account'7import { UpdateAccountParams } from '@/domain/usecases/account/update-account'8import { getRepository } from 'typeorm'9import { AccountEntity } from './account-entity'10export class AccountRepository implements AddAccountRepository, FindAccountByEmailRepository, FindAccountByIdRepository, UpdateAccountRepository, RemoveAccountRepository {11 async add(accountData: AddAccountParams): Promise<AccountModelResponse> {12 const accountEntity = getRepository(AccountEntity)13 const account = accountEntity.create(accountData)14 return await accountEntity.save(account)15 }16 async update(accountId: string, accountData: UpdateAccountParams): Promise<number> {17 const accountEntity = getRepository(AccountEntity)18 const respondeDb = await accountEntity.update(accountId, accountData)19 return respondeDb.affected20 }21 async remove(accountId: string): Promise<number> {22 const accountEntity = getRepository(AccountEntity)23 const dbResponse = await accountEntity.delete(accountId)24 return dbResponse.affected25 }26 async findByEmail(email: string): Promise<AccountModel> {27 const accountEntity = getRepository(AccountEntity)28 const account = await accountEntity29 .createQueryBuilder('account')30 .select([31 'account.id',32 'account.name',33 'account.email',34 'account.password'35 ])36 .where('account.email = :email', { email: email })37 .getOne()38 return account39 }40 async findById(id: string): Promise<AccountModelResponse> {41 const accountEntity = getRepository(AccountEntity)42 const account = await accountEntity43 .createQueryBuilder('account')44 .select([45 'account.id',46 'account.name',47 'account.email',48 'account.created_at',49 'account.updated_at'50 ])51 .where('account.id = :id', { id: id })52 .getOne()53 return account54 }...
Using AI Code Generation
1import Account from "storybook-root/Account";2import Account from "storybook-root/Account";3import Account from "storybook-root/Account";4import Account from "storybook-root/Account";5import Account from "storybook-root/Account";6import Account from "storybook-root/Account";7import Account from "storybook-root/Account";8import Account from "storybook-root/Account";9import Account from "storybook-root/Account";10import Account from "storybook-root/Account";11import Account from "storybook-root/Account";12import Account from "storybook-root/Account";13import Account from "storybook-root/Account";14import Account from "storybook-root/Account";15import Account from "storybook-root/Account";16import Account from "storybook-root/Account";17import Account from "storybook-root/Account";18import Account from "storybook-root/Account";19import Account from "storybook-root/Account";20import Account from "storybook-root/Account";21import Account from "storybook-root/Account";22import Account from "storybook-root/Account";
Using AI Code Generation
1const { account } = require("storybook-root");2account();3const { account } = require("storybook-root");4account();5const { login } = require("storybook-root");6login();7const { logout } = require("storybook-root");8logout();9const { signup } = require("storybook-root");10signup();11const { edit } = require("storybook-root");12edit();13const { delete } = require("storybook-root");14delete();15const { get } = require("storybook-root");16get();17const { list } = require("storybook-root");18list();19const { find } = require("storybook-root");20find();21const { findMany } = require("storybook-root");
Using AI Code Generation
1import { account } from "storybook-root";2console.log(account);3If you get this error, it means that `storybook-root` is not defined. This can happen if you are using a bundler that does not support `module` or `main` fields in `package.json` (like Webpack). In that case, you need to use the `storybook-root` package directly:4import { account } from "storybook-root/dist";5console.log(account);6If you get this error, it means that `storybook-root` is not defined. This can happen if you are using a bundler that does not support `module` or `main` fields in `package.json` (like Webpack). In that case, you need to use the `storybook-root` package directly:7import { account } from "storybook-root/dist";8console.log(account);9If you get this error, it means that `storybook-root` is not defined. This can happen if you are using a bundler that does not support `module` or `main` fields in `package.json` (like Webpack). In that case, you need to use the `storybook-root` package directly:10import { account } from "storybook-root/dist";11console.log(account);12If you get this error, it means that `storybook-root` is not defined. This can happen if you are using a bundler that does not support `module` or `main` fields in `package.json` (like Webpack). In that case, you need to use the `storybook-root` package directly:13import { account } from "storybook-root/dist";14console.log(account);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!