Best JavaScript code snippet using wpt
main-payloadverify.test.js
Source:main-payloadverify.test.js
...38 };39 }40 inst._payloadVerify(payload);41 }42 function makePayload(mutate,extendBase = {}) {43 const payload = {44 ...{45 clientIp: '127.0.0.1',46 headers: {47 'header-key': [48 {49 key: 'Header-Key',50 value: 'header-value',51 },52 ],53 },54 method: 'GET',55 querystring: '',56 uri: '/',57 },58 ...extendBase,59 };60 if (mutate) {61 mutate(payload);62 }63 return payload;64 }65 function makePayloadWithBody(mutate) {66 return makePayload(67 mutate,68 {69 body: {70 action: 'read-only',71 data: '',72 encoding: 'base64',73 inputTruncated: false,74 }75 }76 );77 }78 // test: passing a valid payload79 callVerify(makePayload());80 callVerify(makePayload(function(payload) {81 payload.method = 'POST';82 }));83 // test: payload must be an object84 assert.throws(function() { callVerify(undefined); });85 // test: payload missing/invalid property values86 assert.throws(function() {87 callVerify(makePayload(function(payload) {88 delete payload.clientIp;89 }));90 });91 assert.throws(function() {92 callVerify(makePayload(function(payload) {93 payload.clientIp = -1;94 }));95 });96 assert.throws(function() {97 callVerify(makePayload(function(payload) {98 delete payload.headers;99 }));100 });101 assert.throws(function() {102 callVerify(makePayload(function(payload) {103 payload.headers = -1;104 }));105 });106 assert.throws(function() {107 callVerify(makePayload(function(payload) {108 payload.headers = {109 'UPPER-CASE': [],110 };111 }));112 });113 assert.throws(function() {114 callVerify(makePayload(function(payload) {115 payload.headers = {116 'header-key': -1,117 };118 }));119 });120 assert.throws(function() {121 callVerify(makePayload(function(payload) {122 payload.headers = {123 'header-key': [-1],124 };125 }));126 });127 assert.throws(function() {128 callVerify(makePayload(function(payload) {129 payload.headers = {130 'header-key': [{}],131 };132 }));133 });134 assert.throws(function() {135 callVerify(makePayload(function(payload) {136 payload.headers = {137 'header-key': [{138 value: -1,139 }],140 };141 }));142 });143 assert.throws(function() {144 callVerify(makePayload(function(payload) {145 payload.headers = {146 'header-key': [{147 key: -1,148 value: 'header-value',149 }],150 };151 }));152 });153 assert.throws(function() {154 callVerify(makePayload(function(payload) {155 payload.headers = {156 'header-key': [{157 key: 'Different-Header-Key',158 value: 'header-value',159 }],160 };161 }));162 });163 assert.throws(function() {164 callVerify(makePayload(function(payload) {165 delete payload.method;166 }));167 });168 assert.throws(function() {169 callVerify(makePayload(function(payload) {170 payload.method = -1;171 }));172 });173 assert.throws(function() {174 callVerify(makePayload(function(payload) {175 payload.method = 'invalid_http_method';176 }));177 });178 assert.throws(function() {179 callVerify(makePayload(function(payload) {180 delete payload.querystring;181 }));182 });183 assert.throws(function() {184 callVerify(makePayload(function(payload) {185 payload.querystring = -1;186 }));187 });188 assert.throws(function() {189 callVerify(makePayload(function(payload) {190 delete payload.uri;191 }));192 });193 assert.throws(function() {194 callVerify(makePayload(function(payload) {195 payload.uri = -1;196 }));197 });198 assert.throws(function() {199 callVerify(makePayload(function(payload) {200 payload.uri = 'no_leading_slash';201 }));202 });203 // test: optional `body` property is present204 // test: passing a valid payload205 callVerify(makePayloadWithBody());206 callVerify(makePayloadWithBody(function(payload) {207 payload.body.action = 'replace';208 }));209 callVerify(makePayloadWithBody(function(payload) {210 payload.body.encoding = 'text';211 }));212 // test: given `body` must be an object213 assert.throws(function() {214 callVerify(makePayloadWithBody(function(payload) {215 payload.body = -1;216 }));217 });218 // test: payload missing/invalid property values219 assert.throws(function() {220 callVerify(makePayloadWithBody(function(payload) {221 delete payload.body.action;222 }));223 });224 assert.throws(function() {225 callVerify(makePayloadWithBody(function(payload) {226 payload.body.action = -1;227 }));228 });229 assert.throws(function() {230 callVerify(makePayloadWithBody(function(payload) {231 payload.body.action = 'invalid';232 }));233 });234 assert.throws(function() {235 callVerify(makePayloadWithBody(function(payload) {236 delete payload.body.data;237 }));238 });239 assert.throws(function() {240 callVerify(makePayloadWithBody(function(payload) {241 payload.body.data = -1;242 }));243 });244 assert.throws(function() {245 callVerify(makePayloadWithBody(function(payload) {246 delete payload.body.encoding;247 }));248 });249 assert.throws(function() {250 callVerify(makePayloadWithBody(function(payload) {251 payload.body.encoding = -1;252 }));253 });254 assert.throws(function() {255 callVerify(makePayloadWithBody(function(payload) {256 payload.body.encoding = 'invalid';257 }));258 });259 assert.throws(function() {260 callVerify(makePayloadWithBody(function(payload) {261 delete payload.body.inputTruncated;262 }));263 });264}265function testPayloadVerifyRequestOrigin(inst) {266 function callVerify(payload) {267 inst._payloadVerify(payload);268 }269 function makePayload(mutate,extendBase = {}) {270 const payload = {271 ...{272 clientIp: '127.0.0.1',273 headers: {},274 method: 'GET',275 querystring: '',276 uri: '/',277 },278 ...extendBase,279 };280 if (mutate) {281 mutate(payload);282 }283 return payload;284 }285 function makePayloadWithOriginCustom(mutate) {286 return makePayload(287 mutate,288 {289 origin: {290 custom: {291 customHeaders: {292 'header-key': [293 {294 key: 'Header-Key',295 value: 'header-value',296 },297 ],298 },299 domainName: 'example.org',300 keepaliveTimeout: 1,301 path: '/',302 port: 443,303 protocol: 'https',304 readTimeout: 4,305 sslProtocols: [],306 }307 }308 }309 );310 }311 function makePayloadWithOriginS3(mutate) {312 return makePayload(313 mutate,314 {315 origin: {316 s3: {317 authMethod: 'none',318 customHeaders: {319 'header-key': [320 {321 key: 'Header-Key',322 value: 'header-value',323 },324 ],325 },326 domainName: 'bucket.s3.us-east-1.amazonaws.com',327 path: '/',328 region: 'us-east-1',329 }330 }331 }332 );333 }334 // test: origin must be an object335 assert.throws(function() {336 callVerify(makePayload(function(payload) {337 payload.origin = -1;338 }));339 });340 // test: origin must contain *just one* of `custom` or `s3` - but never both341 assert.throws(function() {342 callVerify(makePayload(function(payload) {343 // provided both344 payload.origin = {345 custom: {},346 s3: {},347 };348 }));349 });350 assert.throws(function() {351 callVerify(makePayload(function(payload) {352 // provided neither353 payload.origin = {};354 }));355 });356 // test: origin [custom]357 // test: passing a valid payload358 callVerify(makePayloadWithOriginCustom());359 callVerify(makePayloadWithOriginCustom(function(payload) {360 payload.origin.custom.port = 80;361 }));362 callVerify(makePayloadWithOriginCustom(function(payload) {363 payload.origin.custom.port = 1024;364 }));365 callVerify(makePayloadWithOriginCustom(function(payload) {366 payload.origin.custom.protocol = 'http';367 }));368 callVerify(makePayloadWithOriginCustom(function(payload) {369 payload.origin.custom.sslProtocols = ['TLSv1.2'];370 }));371 // test: payload missing/invalid property values372 assert.throws(function() {373 callVerify(makePayloadWithOriginCustom(function(payload) {374 payload.origin.custom = -1; // `origin.custom` must be an object375 }));376 });377 assert.throws(function() {378 callVerify(makePayloadWithOriginCustom(function(payload) {379 delete payload.origin.custom.customHeaders;380 }));381 });382 assert.throws(function() {383 callVerify(makePayloadWithOriginCustom(function(payload) {384 payload.origin.custom.customHeaders = -1;385 }));386 });387 assert.throws(function() {388 callVerify(makePayloadWithOriginCustom(function(payload) {389 payload.origin.custom.customHeaders = {390 'UPPER-CASE': [],391 };392 }));393 });394 assert.throws(function() {395 callVerify(makePayloadWithOriginCustom(function(payload) {396 payload.origin.custom.customHeaders = {397 'header-key': -1,398 };399 }));400 });401 assert.throws(function() {402 callVerify(makePayloadWithOriginCustom(function(payload) {403 payload.origin.custom.customHeaders = {404 'header-key': [-1],405 };406 }));407 });408 assert.throws(function() {409 callVerify(makePayloadWithOriginCustom(function(payload) {410 payload.origin.custom.customHeaders = {411 'header-key': [{}],412 };413 }));414 });415 assert.throws(function() {416 callVerify(makePayloadWithOriginCustom(function(payload) {417 payload.origin.custom.customHeaders = {418 'header-key': [{419 value: -1,420 }],421 };422 }));423 });424 assert.throws(function() {425 callVerify(makePayloadWithOriginCustom(function(payload) {426 payload.origin.custom.customHeaders = {427 'header-key': [{428 key: -1,429 value: 'header-value',430 }],431 };432 }));433 });434 assert.throws(function() {435 callVerify(makePayloadWithOriginCustom(function(payload) {436 payload.origin.custom.customHeaders = {437 'header-key': [{438 key: 'Different-Header-Key',439 value: 'header-value',440 }],441 };442 }));443 });444 assert.throws(function() {445 callVerify(makePayloadWithOriginCustom(function(payload) {446 delete payload.origin.custom.domainName;447 }));448 });449 assert.throws(function() {450 callVerify(makePayloadWithOriginCustom(function(payload) {451 payload.origin.custom.domainName = -1;452 }));453 });454 assert.throws(function() {455 callVerify(makePayloadWithOriginCustom(function(payload) {456 payload.origin.custom.domainName = '';457 }));458 });459 assert.throws(function() {460 callVerify(makePayloadWithOriginCustom(function(payload) {461 delete payload.origin.custom.keepaliveTimeout;462 }));463 });464 assert.throws(function() {465 callVerify(makePayloadWithOriginCustom(function(payload) {466 payload.origin.custom.keepaliveTimeout = 'invalid';467 }));468 });469 assert.throws(function() {470 callVerify(makePayloadWithOriginCustom(function(payload) {471 payload.origin.custom.keepaliveTimeout = 0;472 }));473 });474 assert.throws(function() {475 callVerify(makePayloadWithOriginCustom(function(payload) {476 payload.origin.custom.keepaliveTimeout = 61;477 }));478 });479 assert.throws(function() {480 callVerify(makePayloadWithOriginCustom(function(payload) {481 delete payload.origin.custom.path;482 }));483 });484 assert.throws(function() {485 callVerify(makePayloadWithOriginCustom(function(payload) {486 payload.origin.custom.path = -1;487 }));488 });489 assert.throws(function() {490 callVerify(makePayloadWithOriginCustom(function(payload) {491 payload.origin.custom.path = 'invalid';492 }));493 });494 assert.throws(function() {495 callVerify(makePayloadWithOriginCustom(function(payload) {496 payload.origin.custom.path = '/invalid/';497 }));498 });499 assert.throws(function() {500 callVerify(makePayloadWithOriginCustom(function(payload) {501 delete payload.origin.custom.port;502 }));503 });504 assert.throws(function() {505 callVerify(makePayloadWithOriginCustom(function(payload) {506 payload.origin.custom.port = 'invalid';507 }));508 });509 assert.throws(function() {510 callVerify(makePayloadWithOriginCustom(function(payload) {511 payload.origin.custom.port = 666;512 }));513 });514 assert.throws(function() {515 callVerify(makePayloadWithOriginCustom(function(payload) {516 delete payload.origin.custom.protocol;517 }));518 });519 assert.throws(function() {520 callVerify(makePayloadWithOriginCustom(function(payload) {521 payload.origin.custom.protocol = -1;522 }));523 });524 assert.throws(function() {525 callVerify(makePayloadWithOriginCustom(function(payload) {526 payload.origin.custom.protocol = 'invalid';527 }));528 });529 assert.throws(function() {530 callVerify(makePayloadWithOriginCustom(function(payload) {531 delete payload.origin.custom.readTimeout;532 }));533 });534 assert.throws(function() {535 callVerify(makePayloadWithOriginCustom(function(payload) {536 payload.origin.custom.readTimeout = 'invalid';537 }));538 });539 assert.throws(function() {540 callVerify(makePayloadWithOriginCustom(function(payload) {541 payload.origin.custom.readTimeout = 3;542 }));543 });544 assert.throws(function() {545 callVerify(makePayloadWithOriginCustom(function(payload) {546 payload.origin.custom.readTimeout = 61;547 }));548 });549 assert.throws(function() {550 callVerify(makePayloadWithOriginCustom(function(payload) {551 delete payload.origin.custom.sslProtocols;552 }));553 });554 assert.throws(function() {555 callVerify(makePayloadWithOriginCustom(function(payload) {556 payload.origin.custom.sslProtocols = 'not_array';557 }));558 });559 assert.throws(function() {560 callVerify(makePayloadWithOriginCustom(function(payload) {561 payload.origin.custom.sslProtocols = ['invalid_proto'];562 }));563 });564 // test: origin [s3]565 // test: passing a valid payload566 callVerify(makePayloadWithOriginS3());567 callVerify(makePayloadWithOriginS3(function(payload) {568 payload.origin.s3.authMethod = 'origin-access-identity';569 }));570 // test: payload missing/invalid property values571 assert.throws(function() {572 callVerify(makePayloadWithOriginS3(function(payload) {573 payload.origin.s3 = -1; // `origin.s3` must be an object574 }));575 });576 assert.throws(function() {577 callVerify(makePayloadWithOriginS3(function(payload) {578 delete payload.origin.s3.authMethod;579 }));580 });581 assert.throws(function() {582 callVerify(makePayloadWithOriginS3(function(payload) {583 payload.origin.s3.authMethod = -1;584 }));585 });586 assert.throws(function() {587 callVerify(makePayloadWithOriginS3(function(payload) {588 payload.origin.s3.authMethod = 'invalid';589 }));590 });591 assert.throws(function() {592 callVerify(makePayloadWithOriginS3(function(payload) {593 delete payload.origin.s3.customHeaders;594 }));595 });596 assert.throws(function() {597 callVerify(makePayloadWithOriginS3(function(payload) {598 payload.origin.s3.customHeaders = -1;599 }));600 });601 assert.throws(function() {602 callVerify(makePayloadWithOriginS3(function(payload) {603 payload.origin.s3.customHeaders = {604 'UPPER-CASE': [],605 };606 }));607 });608 assert.throws(function() {609 callVerify(makePayloadWithOriginS3(function(payload) {610 payload.origin.s3.customHeaders = {611 'header-key': -1,612 };613 }));614 });615 assert.throws(function() {616 callVerify(makePayloadWithOriginS3(function(payload) {617 payload.origin.s3.customHeaders = {618 'header-key': [-1],619 };620 }));621 });622 assert.throws(function() {623 callVerify(makePayloadWithOriginS3(function(payload) {624 payload.origin.s3.customHeaders = {625 'header-key': [{}],626 };627 }));628 });629 assert.throws(function() {630 callVerify(makePayloadWithOriginS3(function(payload) {631 payload.origin.s3.customHeaders = {632 'header-key': [{633 value: -1,634 }],635 };636 }));637 });638 assert.throws(function() {639 callVerify(makePayloadWithOriginS3(function(payload) {640 payload.origin.s3.customHeaders = {641 'header-key': [{642 key: -1,643 value: 'header-value',644 }],645 };646 }));647 });648 assert.throws(function() {649 callVerify(makePayloadWithOriginS3(function(payload) {650 payload.origin.s3.customHeaders = {651 'header-key': [{652 key: 'Different-Header-Key',653 value: 'header-value',654 }],655 };656 }));657 });658 assert.throws(function() {659 callVerify(makePayloadWithOriginS3(function(payload) {660 delete payload.origin.s3.domainName;661 }));662 });663 assert.throws(function() {664 callVerify(makePayloadWithOriginS3(function(payload) {665 payload.origin.s3.domainName = -1;666 }));667 });668 assert.throws(function() {669 callVerify(makePayloadWithOriginS3(function(payload) {670 payload.origin.s3.domainName = '';671 }));672 });673 assert.throws(function() {674 callVerify(makePayloadWithOriginS3(function(payload) {675 delete payload.origin.s3.path;676 }));677 });678 assert.throws(function() {679 callVerify(makePayloadWithOriginS3(function(payload) {680 payload.origin.s3.path = -1;681 }));682 });683 assert.throws(function() {684 callVerify(makePayloadWithOriginS3(function(payload) {685 payload.origin.s3.path = 'invalid';686 }));687 });688 assert.throws(function() {689 callVerify(makePayloadWithOriginS3(function(payload) {690 payload.origin.s3.path = '/invalid/';691 }));692 });693}694function testPayloadVerifyResponse(inst) {695 function callVerify(payload) {696 inst._payloadVerify(payload);697 }698 function makePayload(mutate) {699 const payload = {700 headers: {701 'header-key': [702 {703 key: 'Header-Key',704 value: 'header-value',705 },706 ],707 },708 status: '200',709 statusDescription: 'OK',710 };711 if (mutate) {712 mutate(payload);713 }714 return payload;715 }716 // test: passing a valid payload717 callVerify(makePayload());718 callVerify(makePayload(function(payload) {719 payload.status = '404';720 payload.statusDescription = 'Not Found';721 }));722 // test: payload must be an object723 assert.throws(function() { callVerify(undefined); });724 // test: payload missing/invalid property values725 assert.throws(function() {726 callVerify(makePayload(function(payload) {727 delete payload.headers;728 }));729 });730 assert.throws(function() {731 callVerify(makePayload(function(payload) {732 payload.headers = -1;733 }));734 });735 assert.throws(function() {736 callVerify(makePayload(function(payload) {737 payload.headers = {738 'UPPER-CASE': [],739 };740 }));741 });742 assert.throws(function() {743 callVerify(makePayload(function(payload) {744 payload.headers = {745 'header-key': -1,746 };747 }));748 });749 assert.throws(function() {750 callVerify(makePayload(function(payload) {751 payload.headers = {752 'header-key': [-1],753 };754 }));755 });756 assert.throws(function() {757 callVerify(makePayload(function(payload) {758 payload.headers = {759 'header-key': [{}],760 };761 }));762 });763 assert.throws(function() {764 callVerify(makePayload(function(payload) {765 payload.headers = {766 'header-key': [{767 value: -1,768 }],769 };770 }));771 });772 assert.throws(function() {773 callVerify(makePayload(function(payload) {774 payload.headers = {775 'header-key': [{776 key: -1,777 value: 'header-value',778 }],779 };780 }));781 });782 assert.throws(function() {783 callVerify(makePayload(function(payload) {784 payload.headers = {785 'header-key': [{786 key: 'Different-Header-Key',787 value: 'header-value',788 }],789 };790 }));791 });792 assert.throws(function() {793 callVerify(makePayload(function(payload) {794 delete payload.status;795 }));796 });797 assert.throws(function() {798 callVerify(makePayload(function(payload) {799 payload.status = -1;800 }));801 });802 assert.throws(function() {803 callVerify(makePayload(function(payload) {804 payload.status = '999'; // unknown HTTP status code805 }));806 });807 assert.throws(function() {808 callVerify(makePayload(function(payload) {809 delete payload.statusDescription;810 }));811 });812 assert.throws(function() {813 callVerify(makePayload(function(payload) {814 payload.statusDescription = -1;815 }));816 });817}...
keys.test.ts
Source:keys.test.ts
...35});36describe('AttributesUtil', () => {37 describe('#getValue()', () => {38 it('should retrieve first level value', () => {39 expect(Keys.getValues(makePayload(), 'last_name')).to.deep.equal(['Doe']);40 });41 it('should return nested value', () => {42 expect(Keys.getValues(makePayload(), 'preferences.email.news')).to.deep.equal([true]);43 });44 it('should return undefined for non existing deep value', () => {45 expect(Keys.getValues(makePayload(), 'preferences.foo.bar')).to.deep.equal([undefined]);46 });47 it('should return array values', () => {48 expect(Keys.getValues(makePayload(), 'posts.[].comments.[].content')).to.deep.equal(['Super cool', 'Ugh?', undefined, undefined]);49 });50 it('should return primitive array values', () => {51 expect(Keys.getValues(makePayload(), 'posts.[].tags.[]')).to.deep.equal([undefined, 'acl', 'abac']);52 });53 it('should retrieve values from an array', () => {54 const payload = makePayload();55 expect(Keys.getValues([payload.posts[0], makePayload().posts[1]], 'comments.[].content')).to.deep.equal(['Super cool', 'Ugh?', undefined, undefined]);56 });57 });58 describe('#filter()', () => {59 it('should keep first level property', () => {60 const filtered = Keys.filter(makePayload(), 'first_name');61 expect(filtered).to.deep.equal({ first_name: 'John' });62 });63 it('should keep multiple first level property', () => {64 const filtered = Keys.filter(makePayload(), ['last_name', 'first_name']);65 expect(filtered).to.deep.equal({ first_name: 'John', last_name: 'Doe' });66 });67 it('should keep nested property', () => {68 const filtered = Keys.filter(makePayload(), 'preferences.email.news');69 expect(filtered).to.deep.equal({ preferences: { email: { news: true } } });70 });71 it('should keep nested array property', () => {72 const filtered = Keys.filter(makePayload(), 'posts.[].title');73 expect(filtered).to.deep.equal({ posts: [{ title: 'RBAC' }, { title: 'ABAC' }] });74 });75 it('should keep full array', () => {76 const filtered = Keys.filter(makePayload(), 'posts');77 expect(filtered).to.deep.equal({78 posts: [{79 id: 1,80 title: 'RBAC',81 content: 'Lorem ipsum',82 comments: [{83 user_id: 3,84 content: 'Super cool'85 }, {86 user_id: 18,87 content: 'Ugh?'88 }, {89 user_id: 1390 }],91 self_comment: 'Do not disclose',92 rating: '**'93 }, {94 id: 2,95 title: 'ABAC',96 content: 'Lorem ipsum',97 rating: '***',98 tags: ['acl', 'abac']99 }]100 });101 });102 it('should keep all but negated', () => {103 const filtered = Keys.filter(makePayload(), ['!password', '!posts', '!preferences.email']);104 expect(filtered).to.deep.equal({105 id: 1,106 first_name: 'John',107 last_name: 'Doe',108 password_reset_required: false,109 preferences: {110 sms: { newComment: true }111 },112 });113 });114 it('should not mismatch similar properties', () => {115 expect(Keys.filter(makePayload(), ['password'])).to.deep.equal({ password: 'p@ssw0rd' });116 });117 it('should mismatch similar properties', () => {118 expect(Keys.filter(makePayload(), ['password*'])).to.deep.equal({ password: 'p@ssw0rd', password_reset_required: false });119 });120 it('should keep nothing', () => {121 const filtered = Keys.filter(makePayload(), []);122 expect(filtered).to.deep.equal({});123 });124 it('should keep everything', () => {125 const payload = makePayload();126 const filtered = Keys.filter(payload, '*');127 expect(filtered).to.deep.equal(payload);128 });129 it('should filter an array', () => {130 const data = [{ foo: 'foo', bar: 'bar' }, { foo: 'bar', bar: 'foo' }];131 expect(Keys.filter(data, 'foo')).to.deep.equal([{ foo: 'foo' }, { foo: 'bar' }]);132 });133 it('should return an array with empty objects', () => {134 const data = [{ foo: 'foo', bar: 'bar' }, { foo: 'bar', bar: 'foo' }];135 expect(Keys.filter(data, [])).to.deep.equal([{}, {}]);136 });137 it('should keep nested properties', () => {138 const filtered = Keys.filter(makePayload(), ['preferences.*']);139 expect(filtered).to.deep.equal({140 preferences: {141 email: { news: true, newPost: false },142 sms: { newComment: true }143 }144 });145 });146 it('should throw if pattern starts with a wild card', () => {147 expect(() => {148 Keys.filter({}, ['*.foo']);149 }).to.throw(/invalid/i);150 });151 it('should throw if pattern starts with unwind', () => {152 expect(() => {153 Keys.filter({}, ['[].foo']);154 }).to.throw(/invalid/i);155 });156 it('should throw if pattern starts with a dot', () => {157 expect(() => {158 Keys.filter({}, ['.foo']);159 }).to.throw(/invalid/i);160 });161 it('should return a new, deep copy of the original object', () => {162 const payload = makePayload();163 const filtered = Keys.filter(payload, '*', false);164 expect(filtered).to.not.equal(payload); // 'reference' (not deep) equality165 });166 it('should return the original object itself', () => {167 const payload = makePayload();168 const filtered = Keys.filter(payload, '*', true);169 expect(filtered).to.equal(payload); // 'reference' (not deep) equality170 });171 });...
sendMessageToBT.js
Source:sendMessageToBT.js
...22}23function connectPayload(connect){24 // connect: boolean25 if(connect){26 return makePayload(67,null, null, null, [67])27 }else{28 return makePayload(67,null, null, null, [68])29 }30 31}32function connectionStatusPayload(){33 return makePayload(78, null, null, null, null);34}35function userMessagePayload(msg){36 return makePayload(77, 83, null, msg, null);37}38function msgAckPayload(){39 return makePayload(77, 82, null, null, null);40}41function pollPayload(reportNumHex){42 console.log("reportNumHex=", reportNumHex)43 return makePayload(80, reportNumHex, null, null, null);44}45function distressPayload(distressOn){46 let distressArr = [];47 if(distressOn==1)48 distressArr = [1]49 else if(distressOn == 0)50 distressArr = [0]51 52 return makePayload(68, null, null, null, distressArr);53}54function pollAckPayload(){55 return makePayload(76, null, null, null, null);56}57function getSettingPayload(){58 return makePayload(83, 82, null, null, null);59}60function setIoportPayload(port1_inout, port1_out, port2_inout, port2_out, port3_inout, port3_out, port4_inout, port4_out){61 //io_inout "00": none "01": digital output "10": digital input "11": analog input62 //io_output "1": high "0": low63 let ioport_status_str_msb = port1_inout + "0" + port1_out + port2_inout + "0" + port2_out;64 let ioport_status_str_lsb = port3_inout + "0" + port3_out + port4_inout + "0" + port4_out;65 return makePayload(83, 87, 49, null, [parseInt(ioport_status_str_msb, 2), parseInt(ioport_status_str_lsb, 2)]);66}67// "01" "1" peiroddtime = number , 68function setReportPayload(reportMaskingBinStr, periodTimeBinStr, ioportStatusBinStr){69 return makePayload(83, 87, null, null, [82, parseInt(reportMaskingBinStr, 2), parseInt(periodTimeBinStr.slice(0, 8), 2), parseInt(periodTimeBinStr.slice(8, 16), 2), parseInt(ioportStatusBinStr.slice(0, 8), 2), parseInt(ioportStatusBinStr.slice(8, 16), 2)]);70}71function getReportSetPayload(){72 return makePayload(83, 82, null, null, null);73}74function networkStatusAck(){75 return makePayload(67, null, null, null, null);76}77function placeAskAck(){78 return makePayload(76, null, null, null, null);79}80function userMessageReceiveAck(){81 return makePayload(78, 82, null, null, null)82}83/*84 arrtypemsg : 10ì§ì ì«ì를 arrayë¡ ì¸ìë¡ ì ê³µ85*/86function makePayload(ctokennum, subctokennum, subtoken2num, msg, arrtypemsg){87 let ret = [];88 89 let ctoken = [ctokennum];90 let subctoken = subctokennum? [subctokennum] : [];91 let subtoken2 = subtoken2num? [subtoken2num] : [];92 let datan = (msg && typeof msg == "string") ? msg.split('').map(x=>x.charCodeAt(0)) : [];93 let datan_arr = arrtypemsg && Array.isArray(arrtypemsg) ? arrtypemsg : [];94 let len = ctoken.length + (subctoken? subctoken.length : 0) + (subtoken2? subtoken2.length : 0) + (datan? datan.length : 0) + (datan_arr? datan_arr.length : 0);95 96 let checksum = (datan_arr.reduce((prev, cur, idx, arr) => {return prev+cur}, 0) + datan.reduce((prev, cur, idx, arr) => {return prev+cur}, 0) + (subctokennum? subctokennum : 0) + (ctokennum) + (subtoken2num? subtoken2num : 0) + len) % 25697 let stx = [2];98 let lenArr = len.toString(16).padStart(4, '0').match(/.{1,2}/g).map(v=>parseInt(v, 16));99 let etx = [3]100 ...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var location = "Dulles:Chrome";4var params = { connectivity: '3G' };5wpt.makePayload(url, location, params, function(err, data) {6 console.log(data);7});8var wpt = require('wpt');9var wpt = new WebPageTest('www.webpagetest.org');10var location = "Dulles:Chrome";11var params = { connectivity: '3G' };12wpt.makePayload(url, location, params, function(err, data) {13 wpt.createTest(data, function(err, data) {14 console.log(data);15 });16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org');
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!!