Best JavaScript code snippet using cavy
Database.ts
Source:Database.ts
...19 var Salt = Security.CreateSalt()20 Database.query(`INSERT INTO authusers(ID, HashedPassword, Salt, SessionID, SignupDate)21 VALUES(${Database.escape(ID)}, '${Security.EncryptPassword(Password, Salt)}', '${Salt}', '', NOW());`, (err, rows, fields) => {22 if (!err) { //ì¤ë¥ê° ìë¤ë©´23 onFinish(TaskCode.SUCCESS_WORK) //ìì
ìë£24 } else { //ì¤ë¥ ë°ì ì25 console.log(err)26 onFinish(TaskCode.ERR_DATABASE_UNKNOWN) //ì ì ìë ì¤ë¥27 }28 29 })30 } else { onFinish(TaskCode.ERR_SIGNUP_EXISTS_ACCOUNT) } //ì¼ì¹íë IDê° ì´ë¯¸ ìë¤ë©´31 })32 })33 }34 //ë¡ê·¸ì¸ 쿼리35 static Signin(ID: string, Password: string, onFinish: (code: TaskCode, newSessionID: string) => any) {36 const Pool = getPool()37 Pool.getConnection((poolErr, Database) => {38 Database.query(`SELECT * FROM authusers WHERE ID=${Database.escape(ID)};`, (err, rows, fields) => {39 if (!err && (rows as any).length == 1) {40 console.log(err)41 var FoundUser = (rows as any)[0]42 var LoginResult: boolean = (FoundUser.HashedPassword == Security.EncryptPassword(Password, FoundUser.Salt))43 if (LoginResult) { //ë¡ê·¸ì¸ ì±ê³µ ì44 var SessionID: string = Security.CreateSessionID()45 Database.query(`UPDATE authusers SET SessionID='${SessionID}' WHERE ID=${Database.escape(ID)};`, (err, rows, fields) => {46 console.log(err)47 if (!err) { //ìë¡ì´ ì¸ì
ID ë°ê¸ ì48 onFinish(TaskCode.SUCCESS_WORK, SessionID)49 50 return51 }52 })53 } else if (!LoginResult) { //íì¤ìëê° í릴 ê²½ì°(* ê²½ê³ : íì¤ìë ì¤ë¥ì ì¼ì¹íë ê³ì ìì ì¤ë¥ë ë³´ìì ìí´ í´ë¼ì´ì¸í¸ìì íëì ì¤ë¥ë¡ íìí ê²!)54 onFinish(TaskCode.ERR_SIGNIN_NOT_EQUAL_PW, "")55 }56 else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN, "") } //ì ì ìë ì¤ë¥57 } else if ((rows as any).length > 1) { onFinish(TaskCode.ERR_SIGNIN_NOT_FOUND, "") } //ì¼ì¹íë ê³ì ì´ ìì58 else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN, "") } //ìììë ì¤ë¥59 60 })61 })62 }63 //기í ìì
ì ì¸ì
ID ì¸ì¦ í¨ì64 static AuthSession(SessionID: string, onFinish: (code: TaskCode, newSessionID: string) => any) {65 const Pool = getPool()66 Pool.getConnection((poolErr, Database) => {67 Database.query(`SELECT * FROM authusers WHERE SessionID=${Database.escape(SessionID)};`, (err, rows, fields) => {68 if (!err && (rows as any).length == 1) { //DB ì¤ë¥ê° ìë¤ë©´69 var CreatedSessionID = Security.CreateSessionID()70 Database.query(`UPDATE authusers SET SessionID='${CreatedSessionID}' WHERE SessionID=${Database.escape(SessionID)};`, (err, rows, fields) => {71 if (!err) { //ìë¡ì´ ì¸ì
ID ë°ê¸ ì72 onFinish(TaskCode.SUCCESS_WORK, CreatedSessionID)73 } else { onFinish(TaskCode.ERR_SESSION_REGEN_FAILED, "") }74 75 return76 })77 } else if ((rows as any).length == 0 || (rows as any).length > 1) { onFinish(TaskCode.ERR_SESSION_AUTH_FAILED, "") } //ì¼ì¹íë ê³ì ì ì°¾ì ì ìì78 else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN, "") } //DB ì¤ë¥ê° ìë¤ë©´79 80 })81 })82 }83 //ì ì´ ê¸°ë¡ ì¶ê°84 static InsertRecord(myStaticID: string, records: Array<string>, onFinish: (code: TaskCode) => any) {85 const Pool = getPool()86 Pool.getConnection((poolErr, Database) => {87 var QueryValues: string[] = records.map((it) =>88 `(${Database.escape(myStaticID)}, ${Database.escape(it)}, ${Database.escape(momentJS(new Date()).tz("Asia/Seoul").format("YYYY-MM-DD"))})` //KST TIMEZONE89 )90 //console.log("ëë²ê·¸" + `INSERT INTO scanchains(ScannerStaticID, ScanedDynamicUUID, ContactDayWithoutTime, Authed) VALUES ${QueryValues.join(",")};` + "ã
ê·¸ë¦¬ê³ ã
" + "INSERT INTO scanchains(ScannerStaticID, ScanedDynamicUUID, ContactDayWithoutTime, Authed) VALUES " + QueryValues.join(",") + ";")91 Database.query(`INSERT INTO scanchains(ScannerStaticID, ScanedDynamicUUID, ContactDayWithoutTime) VALUES ${QueryValues.join(",")};`, (err, rows, fields) => {92 console.log(err)93 if (!err) {94 onFinish(TaskCode.SUCCESS_WORK) //INSERT ì±ê³µ95 } else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN) } //INSERT ì¤ ì¤ë¥ ë°ì ì96 97 })98 })99 }100 //íì§ì ì ì´ì¬ë¶ ê²ì101 static SearchRecord(myStaticID: string, onFinish: (code: TaskCode, found_uuid: Array<string>, found_date: Array<string>) => any) {102 const Pool = getPool()103 Pool.getConnection((poolErr, Database) => {104 Database.query(`SELECT * FROM scanchains WHERE ScannerStaticID=${Database.escape(myStaticID)} AND ContactDayWithoutTime > (NOW() - INTERVAL 1 MONTH);`, (err, rows_my, fields) => {105 if (!err) { //íì§ìë¤ ë¦¬ì¤í¸ìì ì ì ê° ì¤ìºíë ì ì´ê¸°ë¡ë¤ì ì ë¶ ë¶ë¬ì´(ë¨ íë¬ ì ë¶í° ì§ê¸ê¹ì§ ììë 기ë¡ë§ ê°ì ¸ì´)106 if ((rows_my as any).length == 0) { onFinish(TaskCode.SUCCESS_WORK, [], []) } //ì¤ìº ê¸°ë¡ ìì²´ê° ìì ë107 else {108 var myscanedUUIDlist: Array<string> = (rows_my as any).map((it: any) => { return it.ScanedDynamicUUID })109 Database.query(`SELECT * FROM infectedpersons WHERE Authed=1 AND PersonUUID IN (?)`, myscanedUUIDlist, (err, rows, fields) => {110 if (!err) { //ì¸ì¦ë íì§ìë¤ ì¤ìì ë§ë íì§ìê° ìë¤ë©´111 var contactedUUID: Array<string> = (rows as any).map((it: any) => { return it.PersonUUID })112 var contactedDate: Array<string> = (rows as any).map((it: any) => { return it.ContactDayWithoutTime })113 onFinish(TaskCode.SUCCESS_WORK, contactedUUID, contactedDate) //ê° ë°í114 } else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN, [], []) }115 116 })117 }118 } else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN, [], []); }119 })120 })121 }122 //íì§ì ì¶ê°123 static InsertInfection(Records: Array<string>, GovermentEmail: string, GovermentID: string, PhoneLastNumber: string, onFinish: (code: TaskCode, AuthID: string) => any) {124 const Pool = getPool()125 Pool.getConnection((poolErr, Database) => {126 var QueryValues: string[] = Records.map((it) =>127 `(${Database.escape(it)}, ${Database.escape(GovermentID)}, ${Database.escape(PhoneLastNumber)}, ${Database.escape(GovermentEmail)})`128 )129 const EmailAuthID = Security.CreateSessionID()130 Database.query(`INSERT INTO infectedpersons(PersonUUID, GovermentID, PhoneLastNumber, GovermentEMAIL) VALUES ${QueryValues.join(",")};`,131 (err, rows, fields) => { //íì§ì ë±ë¡132 console.log("ì¤ë¥ : " + err?.message + "\n" + err?.code + "\n" + err?.stack) //SQL ëë²ê·¸(ìë íì¸í ì´ ì£¼ìì ì§ì°ê¸°)133 if (!err) {134 Database.query(`INSERT INTO authinfect(EmailAuthID, GovermentID) VALUES('${EmailAuthID}', ${Database.escape(GovermentID)});`,135 (err, rows, fields) => { //ì´ë©ì¼ ë§í¬ ë±ë¡136 console.log("ì¤ë¥ : " + err?.message + "\n" + err?.code) //SQL ëë²ê·¸(ìë íì¸í ì´ ì£¼ìì ì§ì°ê¸°)137 if (!err) {138 onFinish(TaskCode.SUCCESS_WORK, EmailAuthID)139 } else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN, "") }140 141 })142 } else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN, ""); }143 })144 })145 }146 //íì§ì ì¸ì¦147 static AuthInfection(AuthID: string, onFinish: (code: TaskCode) => any) {148 const Pool = getPool()149 Pool.getConnection((poolErr, Database) => { 150 Database.query(`SELECT * FROM authinfect WHERE EmailAuthID=${Database.escape(AuthID)}`, (err, rows, fields) => { //ì¸ì¦ IDë¡ íì§ìë¤ ID ê°ì ¸ì¤ê¸°151 if (!err && (rows as any).length > 0) { //ì¤ë¥ê° ìë¤ë©´152 Database.query(`UPDATE infectedpersons SET Authed=1 WHERE GovermentID='${(rows as any)[0].GovermentID}'`, (err, rows, fields) => { //íì§ìë¤ IDì ì¼ì¹íë íì§ìë 모ë ì¸ì¦ ì²ë¦¬153 if (!err) {154 Database.query(`DELETE FROM authinfect WHERE EmailAuthID=${Database.escape(AuthID)}`)155 onFinish(TaskCode.SUCCESS_WORK)156 } else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN) }157 })158 } else { onFinish(TaskCode.ERR_DATABASE_UNKNOWN) }159 })160 })161 }162}163//ë°ì´í°ë² ì´ì¤ ê´ë ¨ ìì
ê²°ê³¼ ì½ë164enum TaskCode {165 //ì±ê³µì166 SUCCESS_WORK, //ë°ì´í°ë² ì´ì¤ ì¿¼ë¦¬ê° ì ìì ì¼ë¡ ìëíì ë167 //ë²ì© ë°ì´í°ë² ì´ì¤ ì¤ë¥168 ERR_DATABASE_NOT_CONNECT, //ë°ì´í°ë² ì´ì¤ ì°ê²°ì´ ìë ë169 ERR_DATABASE_UNKNOWN, //ìë ¤ì§ì§ ìì ì¤ë¥170 ERR_INVALID_VALUE, //ì¬ë°ë¥´ì§ ìì ì
ë ¥ê°171 //íìê°ì
ë° ë¡ê·¸ì¸ ì¤ë¥172 ERR_SIGNUP_EXISTS_ACCOUNT, //íìê°ì
ì ê³ì ì´ ì´ë¯¸ ì¡´ì¬í ë...
action.ts
Source:action.ts
...50 name,51 },52 });53 if (onFinish) {54 onFinish();55 }56 toast('Department Created Successfully');57 console.log('ð ~ file: action.ts ~ line 22 ~ result', res);58 } catch (e) {59 console.log('e', e);60 toast(e);61 dispatch({62 type: 'CREATE_OR_UPDATE',63 payload: false,64 });65 if (onFinish) {66 onFinish();67 }68 }69 };70export const updateDepartment =71 (payload, id, onFinish) => async (dispatch: Dispatch) => {72 try {73 dispatch({74 type: 'CREATE_OR_UPDATE',75 payload: true,76 });77 const {name} = payload;78 await httpClient(`/department/${id}`, {79 method: 'PUT',80 body: {81 name,82 },83 });84 toast('Department Updated Successfully');85 if (onFinish) {86 onFinish();87 }88 } catch (e) {89 console.log('e', e);90 toast(e);91 dispatch({92 type: 'CREATE_OR_UPDATE',93 payload: false,94 });95 if (onFinish) {96 onFinish();97 }98 }99 };100export const deleteDepartment =101 (id, onFinish) => async (dispatch: Dispatch) => {102 try {103 dispatch({104 type: 'CREATE_OR_UPDATE',105 payload: true,106 });107 const res = await httpClient(`/department/${id}`, {108 method: 'DELETE',109 });110 toast('Sucessfully deleted!');111 if (onFinish) {112 onFinish();113 }114 } catch (e) {115 toast('Somthing Went Wrong!', {116 type: 'error',117 });118 dispatch({119 type: 'CREATE_OR_UPDATE',120 payload: false,121 });122 if (onFinish) {123 onFinish();124 }125 }126 };127 // Department Actions128export const getAllEmployee =129(payload = {130 searchQuery:'',131 page:0,132 pageSize:5133}) =>134async (dispatch: Dispatch) => {135 try {136 dispatch({137 type: 'LOADING',...
Manager.js
Source:Manager.js
1/**2 * @todo -> irgendwann als package manager3 */4define('classes/plugins/Manager', [5 'qui/QUI',6 'qui/classes/DOM',7 'classes/plugins/Plugin',8 'qui/utils/Object',9 'Ajax',10 'Plugins',11 'Projects'12], function (QUI, DOM, Plugin, ObjectUtils, Ajax, Plugins, Projects) {13 "use strict";14 return new Class({15 Extends: DOM,16 Type : 'classes/plugins/Manager',17 initialize: function (options) {18 this.parent(options);19 this.$plugins = {};20 this.$typesNames = {};21 },22 /**23 * create an Plugin24 *25 * @param plugin - String: Plugin Name26 * @param options - Plugin Params27 * events28 * methods29 */30 create: function (plugin, options) {31 options = options || {};32 options.name = plugin;33 this.$plugins[plugin] = new Plugin(options);34 },35 get: function (plugin, onfinish) {36 if (this.$plugins[plugin]) {37 this.$get(plugin, onfinish);38 return;39 }40 if (typeof QUI.MVC.plugins[plugin] === 'undefined') {41 onfinish(false);42 return;43 }44 QUI.MVC.require([plugin], function (plugin, onfinish) {45 this.$get(plugin, onfinish);46 }.bind(this, [plugin, onfinish]));47 },48 /**49 * Load ausführen50 */51 $get: function (plugin, onfinish) {52 if (this.$plugins[plugin].isLoaded()) {53 onfinish(this.$plugins[plugin]);54 return;55 }56 this.$plugins[plugin].load(function () {57 onfinish(this.$plugins[plugin]);58 }.bind(this, [plugin, onfinish]));59 },60 /**61 * Return the name of a type62 *63 * @param {String} type64 * @param {Function} [onfinish]65 * @param {Object} [params]66 */67 getTypeName: function (type, onfinish, params) {68 if (typeof this.$typesNames[type] !== 'undefined') {69 if (typeof onfinish === 'function') {70 onfinish(this.$typesNames[type]);71 }72 return;73 }74 params = ObjectUtils.combine(params, {75 sitetype: type76 });77 Ajax.get('ajax_project_types_get_title', function (result) {78 if (typeof onfinish === 'function') {79 onfinish(result);80 }81 }, params);82 },83 /**84 * Return all available types of a project85 *86 * @param {String} project - project name87 * @param {Function} [onfinish] - callback88 * @param {Object} [params]89 */90 getTypes: function (project, onfinish, params) {91 var Project = Projects.get();92 if (typeof project !== 'undefined') {93 Project = Projects.get(project);94 }95 params = params || {};96 params.project = Project.encode();97 Ajax.get('ajax_project_types_get_list', function (result, Ajax) {98 if (typeof onfinish === 'function') {99 onfinish(result, Ajax);100 }101 }, params);102 }103 });...
Using AI Code Generation
1import { afterAll, beforeAll } from 'cavy';2beforeAll(async () => {3 await device.launchApp({ permissions: { notifications: 'YES' } });4});5afterAll(async () => {6 await device.terminateApp();7});8import { spec } from 'cavy';9const testHook = spec(test);10describe('My App', function() {11 testHook('Should do something', async function() {12 await expect(element(by.id('some-id'))).toExist();13 });14});15describe('My App', function() {16 testHook('Should do something', async function() {17 await expect(element(by.id('some-id'))).toExist();18 });19});20it('Should do something', async function() {21 await expect(element(by.id('some-id'))).toExist();22});23#### `expect(element(by.id('some-id'))).toExist()`24#### `expect(element(by.id('some-id'))).toHaveText('Some text')`25#### `expect(element(by.id('some-id'))).toHaveValue('Some value')`26#### `expect(element(by.id('some-id'))).toHaveLabel('Some label')`27#### `expect(element(by.id('some-id'))).toHaveStyle({ width: 100 })`28#### `expect(element(by.id('some-id'))).toBeVisible()`29#### `expect(element(by.id('some-id'))).toBeNotVisible()`30#### `expect(element(by.id('some-id'))).toBeDisabled()`
Using AI Code Generation
1const spec = async (TestComponent) => {2 describe('TestComponent', () => {3 let component;4 let tester;5 beforeEach(async () => {6 component = await loadComponent(7 );8 tester = await createTester(component);9 });10 it('should have a button', async () => {11 await tester.findComponent('button');12 });13 });14};15const spec = async (TestComponent) => {16 describe('TestComponent', () => {17 let component;18 let tester;19 beforeEach(async () => {20 component = await loadComponent(21 );22 tester = await createTester(component);23 });24 it('should have a button', async () => {25 await tester.findComponent('button');26 });27 });28};29const spec = async (TestComponent) => {30 describe('TestComponent', () => {31 let component;32 let tester;33 beforeEach(async () => {34 component = await loadComponent(35 );36 tester = await createTester(component);37 });38 it('should have a button', async () => {39 await tester.findComponent('button');40 });41 });42};43const spec = async (TestComponent) => {44 describe('TestComponent', () => {45 let component;46 let tester;47 beforeEach(async () => {48 component = await loadComponent(49 );50 tester = await createTester(component);51 });52 it('should have a button', async () => {53 await tester.findComponent('button');54 });55 });56};57const spec = async (TestComponent) => {58 describe('TestComponent', () => {59 let component;60 let tester;61 beforeEach(async () => {62 component = await loadComponent(63 );64 tester = await createTester(component);65 });66 it('should have a button', async () => {67 await tester.findComponent('button');68 });69 });70};71const spec = async (TestComponent) => {72 describe('TestComponent', () => {73 let component;74 let tester;75 beforeEach(async () => {
Using AI Code Generation
1const spec = async (test) => {2 await test('should render the correct text', async (t) => {3 await t.expect(element(by.id('text'))).toHaveText('Hello, world!');4 });5};6const specWithFinish = async (test) => {7 await test('should render the correct text', async (t) => {8 await t.expect(element(by.id('text'))).toHaveText('Hello, world!');9 });10};11module.exports = {12};13import { spec, specWithFinish } from './TestComponent';14describe('Example', () => {15 beforeAll(async () => {16 await device.launchApp();17 });18 afterAll(async () => {19 await device.terminateApp();20 });21 describe('Example', () => {22 it('should render the correct text', async () => {23 await spec(test);24 });25 });26});27import { spec, specWithFinish } from './TestComponent';28describe('Example', () => {29 beforeAll(async () => {30 await device.launchApp();31 });32 afterAll(async () => {33 await device.terminateApp();34 });35 describe('Example', () => {36 it('should render the correct text', async () => {37 await spec(test);38 });39 it('should render the correct text', async () => {40 await specWithFinish(test);41 });42 });43});44This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
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!!