Best JavaScript code snippet using wpt
BeaconsRoutesV2.test.ts
Source:BeaconsRoutesV2.test.ts
1const assert = require('chai').assert;2import { DataPage } from 'pip-services3-commons-nodex';3import { Descriptor } from 'pip-services3-commons-nodex';4import { BeaconV1 } from '../../../src/clients/version1/BeaconV1';5import { BeaconsMemoryClientV1 } from '../../../src/clients/version1/BeaconsMemoryClientV1';6import { TestUsers } from '../../fixtures/TestUsers';7import { TestReferences } from '../../fixtures/TestReferences';8import { TestRestClient } from '../../fixtures/TestRestClient';9let BEACON1: BeaconV1 = {10 id: '1',11 udi: '000001',12 site_id: '1',13 label: 'TestBeacon1',14 center: { type: 'Point', coordinates: [0, 0] },15 radius: 5016};17let BEACON2: BeaconV1 = {18 id: '2',19 udi: '000002',20 site_id: '1',21 label: 'TestBeacon2',22 center: { type: 'Point', coordinates: [2, 2] },23 radius: 7024};25let BEACON3: BeaconV1 = {26 id: '3',27 udi: '000003',28 site_id: '2',29 label: 'TestBeacon3',30 center: { type: 'Point', coordinates: [10, 10] },31 radius: 5032};33suite('BeaconsOperationsV2', () => {34 let references: TestReferences;35 let rest: TestRestClient;36 setup(async () => {37 rest = new TestRestClient();38 references = new TestReferences();39 references.put(new Descriptor('beacons', 'client', 'memory', 'default', '1.0'), new BeaconsMemoryClientV1());40 await references.open(null);41 });42 teardown(async () => {43 await references.close(null);44 });45 test('should perform beacon operations', async () => {46 let beacon1, beacon2, beacon3: BeaconV1;47 // Create one beacon48 let beacon = await rest.postAsUser(49 TestUsers.AdminUserSessionId,50 '/api/v2/sites/' + BEACON1.site_id + '/xbeacons',51 BEACON1,52 );53 assert.isObject(beacon);54 assert.equal(beacon.site_id, BEACON1.site_id);55 assert.equal(beacon.udi, BEACON1.udi);56 assert.equal(beacon.label, BEACON1.label);57 assert.isNotNull(beacon.center);58 beacon1 = beacon;59 // Create another beacon60 beacon = await rest.postAsUser(61 TestUsers.AdminUserSessionId,62 '/api/v2/sites/' + BEACON2.site_id + '/xbeacons',63 BEACON264 );65 assert.isObject(beacon);66 assert.equal(beacon.site_id, BEACON2.site_id);67 assert.equal(beacon.udi, BEACON2.udi);68 assert.equal(beacon.label, BEACON2.label);69 assert.isNotNull(beacon.center);70 beacon2 = beacon;71 // Create yet another beacon72 beacon = await rest.postAsUser(73 TestUsers.AdminUserSessionId,74 '/api/v2/sites/' + BEACON3.site_id + '/xbeacons',75 BEACON376 );77 assert.isObject(beacon);78 assert.equal(beacon.site_id, BEACON3.site_id);79 assert.equal(beacon.udi, BEACON3.udi);80 assert.equal(beacon.label, BEACON3.label);81 assert.isNotNull(beacon.center);82 beacon3 = beacon;83 // Get all beacons84 let page: DataPage<BeaconV1> = await rest.getAsUser(85 TestUsers.AdminUserSessionId,86 '/api/v2/sites/' + BEACON1.site_id + '/xbeacons'87 );88 89 assert.isObject(page);90 assert.lengthOf(page.data, 2);91 // Calculate positions92 let position = await rest.postAsUser(93 TestUsers.AdminUserSessionId,94 '/api/v2/sites/' + BEACON1.site_id + '/xbeacons/calculate_position',95 {96 site_id: BEACON1.site_id,97 udis: [BEACON1.udi]98 }99 );100 assert.isObject(position);101 assert.equal(position.type, 'Point');102 // Validate beacon udi103 let result = await rest.postAsUser(104 TestUsers.AdminUserSessionId,105 '/api/v2/sites/' + beacon1.site_id + '/xbeacons/validate_udi?udi=' + beacon1.udi,106 {},107 );108 assert.equal(result, beacon1.id);109 // Update the beacon110 beacon1.label = 'ABC';111 beacon = await rest.putAsUser(112 TestUsers.AdminUserSessionId,113 '/api/v2/sites/' + beacon1.site_id + '/xbeacons/' + beacon1.id,114 beacon1115 );116 assert.isObject(beacon);117 assert.equal(beacon.label, 'ABC');118 // Delete beacon119 beacon = await rest.delAsUser(120 TestUsers.AdminUserSessionId,121 '/api/v2/sites/' + beacon1.site_id + '/xbeacons/' + beacon1.id122 );123 assert.equal(beacon.id, beacon1.id);124 // Try to get delete beacon125 result = await rest.getAsUser(126 TestUsers.AdminUserSessionId,127 '/api/v2/sites/' + beacon1.site_id + '/xbeacons/' + beacon1.id128 );129 assert.isNull(result);130 });...
BeaconsRoutesV1.test.ts
Source:BeaconsRoutesV1.test.ts
1const assert = require('chai').assert;2import { DataPage } from 'pip-services3-commons-nodex';3import { Descriptor } from 'pip-services3-commons-nodex';4import { BeaconV1 } from '../../../src/clients/version1/BeaconV1';5import { BeaconsMemoryClientV1 } from '../../../src/clients/version1/BeaconsMemoryClientV1';6import { TestUsers } from '../../fixtures/TestUsers';7import { TestReferences } from '../../fixtures/TestReferences';8import { TestRestClient } from '../../fixtures/TestRestClient';9let BEACON1: BeaconV1 = {10 id: '1',11 udi: '000001',12 site_id: '1',13 label: 'TestBeacon1',14 center: { type: 'Point', coordinates: [0, 0] },15 radius: 5016};17let BEACON2: BeaconV1 = {18 id: '2',19 udi: '000002',20 site_id: '1',21 label: 'TestBeacon2',22 center: { type: 'Point', coordinates: [2, 2] },23 radius: 7024};25let BEACON3: BeaconV1 = {26 id: '3',27 udi: '000003',28 site_id: '2',29 label: 'TestBeacon3',30 center: { type: 'Point', coordinates: [10, 10] },31 radius: 5032};33suite('BeaconsOperationsV1', () => {34 let references: TestReferences;35 let rest: TestRestClient;36 setup(async () => {37 rest = new TestRestClient();38 references = new TestReferences();39 references.put(new Descriptor('beacons', 'client', 'memory', 'default', '1.0'), new BeaconsMemoryClientV1());40 await references.open(null);41 });42 teardown(async () => {43 await references.close(null);44 });45 test('should perform beacon operations', async () => {46 let beacon1, beacon2, beacon3: BeaconV1;47 // Create one beacon48 let beacon = await rest.postAsUser(49 TestUsers.AdminUserSessionId,50 '/api/v1/sites/' + BEACON1.site_id + '/beacons',51 BEACON1,52 );53 assert.isObject(beacon);54 assert.equal(beacon.site_id, BEACON1.site_id);55 assert.equal(beacon.udi, BEACON1.udi);56 assert.equal(beacon.label, BEACON1.label);57 assert.isNotNull(beacon.center);58 beacon1 = beacon;59 // Create another beacon60 beacon = await rest.postAsUser(61 TestUsers.AdminUserSessionId,62 '/api/v1/sites/' + BEACON2.site_id + '/beacons',63 BEACON264 );65 assert.isObject(beacon);66 assert.equal(beacon.site_id, BEACON2.site_id);67 assert.equal(beacon.udi, BEACON2.udi);68 assert.equal(beacon.label, BEACON2.label);69 assert.isNotNull(beacon.center);70 beacon2 = beacon;71 // Create yet another beacon72 beacon = await rest.postAsUser(73 TestUsers.AdminUserSessionId,74 '/api/v1/sites/' + BEACON3.site_id + '/beacons',75 BEACON376 );77 assert.isObject(beacon);78 assert.equal(beacon.site_id, BEACON3.site_id);79 assert.equal(beacon.udi, BEACON3.udi);80 assert.equal(beacon.label, BEACON3.label);81 assert.isNotNull(beacon.center);82 beacon3 = beacon;83 // Get all beacons84 let page: DataPage<BeaconV1> = await rest.getAsUser(85 TestUsers.AdminUserSessionId,86 '/api/v1/sites/' + BEACON1.site_id + '/beacons'87 );88 89 assert.isObject(page);90 assert.lengthOf(page.data, 2);91 // Calculate positions92 let position = await rest.postAsUser(93 TestUsers.AdminUserSessionId,94 '/api/v1/sites/' + BEACON1.site_id + '/beacons/calculate_position',95 {96 site_id: BEACON1.site_id,97 udis: [BEACON1.udi]98 }99 );100 assert.isObject(position);101 assert.equal(position.type, 'Point');102 // Validate beacon udi103 let result = await rest.postAsUser(104 TestUsers.AdminUserSessionId,105 '/api/v1/sites/' + beacon1.site_id + '/beacons/validate_udi?udi=' + beacon1.udi,106 {},107 );108 assert.equal(result, beacon1.id);109 // Update the beacon110 beacon1.label = 'ABC';111 beacon = await rest.putAsUser(112 TestUsers.AdminUserSessionId,113 '/api/v1/sites/' + beacon1.site_id + '/beacons/' + beacon1.id,114 beacon1115 );116 assert.isObject(beacon);117 assert.equal(beacon.label, 'ABC');118 // Delete beacon119 beacon = await rest.delAsUser(120 TestUsers.AdminUserSessionId,121 '/api/v1/sites/' + beacon1.site_id + '/beacons/' + beacon1.id122 );123 assert.equal(beacon.id, beacon1.id);124 // Try to get delete beacon125 result = await rest.getAsUser(126 TestUsers.AdminUserSessionId,127 '/api/v1/sites/' + beacon1.site_id + '/beacons/' + beacon1.id128 );129 assert.isNull(result);130 });...
BeaconsClientV1Fixture.ts
Source:BeaconsClientV1Fixture.ts
1let _ = require('lodash');2let assert = require('chai').assert;3import { FilterParams } from 'pip-services3-commons-nodex';4import { PagingParams } from 'pip-services3-commons-nodex';5import { BeaconV1 } from '../../src/version1/BeaconV1';6import { BeaconTypeV1 } from '../../src/version1/BeaconTypeV1';7import { IBeaconsClientV1 } from '../../src/version1/IBeaconsClientV1';8const BEACON1: BeaconV1 = {9 id: '1',10 udi: '00001',11 type: BeaconTypeV1.AltBeacon,12 site_id: '1',13 label: 'TestBeacon1',14 center: { type: 'Point', coordinates: [ 0, 0 ] },15 radius: 5016};17const BEACON2: BeaconV1 = {18 id: '2',19 udi: '00002',20 type: BeaconTypeV1.iBeacon,21 site_id: '1',22 label: 'TestBeacon2',23 center: { type: 'Point', coordinates: [ 2, 2 ] },24 radius: 7025};26export class BeaconsClientV1Fixture {27 private _client: IBeaconsClientV1;28 public constructor(client: IBeaconsClientV1) {29 assert.isNotNull(client);30 this._client = client;31 }32 public async testCrudOperations() {33 let beacon1: BeaconV1;34 35 // Create the first beacon36 let beacon = await this._client.createBeacon(null, BEACON1);37 assert.isObject(beacon);38 assert.equal(BEACON1.udi, beacon.udi);39 assert.equal(BEACON1.site_id, beacon.site_id);40 assert.equal(BEACON1.type, beacon.type);41 assert.equal(BEACON1.label, beacon.label);42 assert.isNotNull(beacon.center);43 // Create the second beacon44 beacon = await this._client.createBeacon(null, BEACON2);45 assert.isObject(beacon);46 assert.equal(BEACON2.udi, beacon.udi);47 assert.equal(BEACON2.site_id, beacon.site_id);48 assert.equal(BEACON2.type, beacon.type);49 assert.equal(BEACON2.label, beacon.label);50 assert.isNotNull(beacon.center);51 // Get all entities52 let page = await this._client.getBeacons(null, new FilterParams(), new PagingParams());53 assert.isObject(page);54 assert.lengthOf(page.data, 2);55 beacon1 = page.data[0];56 // Update the beacon57 beacon1.label = 'ABC';58 beacon = await this._client.updateBeacon(null, beacon1);59 assert.isObject(beacon);60 assert.equal(beacon1.id, beacon.id);61 assert.equal('ABC', beacon.label);62 // Get beacon by udi63 beacon = await this._client.getBeaconByUdi(null, beacon1.udi);64 assert.isObject(beacon);65 assert.equal(beacon1.id, beacon.id);66 // Delete the beacon67 beacon = await this._client.deleteBeaconById(null, beacon1.id);68 assert.isObject(beacon);69 assert.equal(beacon1.id, beacon.id);70 // Try to get deleted beacon71 beacon = await this._client.getBeaconById(null, beacon1.id);72 assert.isNull(beacon || null);73 }74 public async testCalculatePosition() {75 // Create the first beacon76 let beacon = await this._client.createBeacon(null, BEACON1,);77 assert.isObject(beacon);78 assert.equal(BEACON1.udi, beacon.udi);79 assert.equal(BEACON1.site_id, beacon.site_id);80 assert.equal(BEACON1.type, beacon.type);81 assert.equal(BEACON1.label, beacon.label);82 assert.isNotNull(beacon.center);83 // Create the second beacon84 beacon = await this._client.createBeacon(null, BEACON2);85 assert.isObject(beacon);86 assert.equal(BEACON2.udi, beacon.udi);87 assert.equal(BEACON2.site_id, beacon.site_id);88 assert.equal(BEACON2.type, beacon.type);89 assert.equal(BEACON2.label, beacon.label);90 assert.isNotNull(beacon.center);91 // Calculate position for one beacon92 let position = await this._client.calculatePosition(93 null, '1', ['00001']);94 assert.isObject(position);95 assert.equal('Point', position.type);96 assert.lengthOf(position.coordinates, 2);97 assert.equal(0, position.coordinates[0]);98 assert.equal(0, position.coordinates[1]);99 }...
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!!