How to use headersMap method in mountebank

Best JavaScript code snippet using mountebank

onboarding.test.js

Source:onboarding.test.js Github

copy

Full Screen

1const { Headers } = require('node-fetch');2const AbortController = require('abort-controller');3const {4 sendRequest,5 settlementIdFromHubAccounts,6 createHubAccount,7 getDfspAccounts,8 addDfsp,9 addInitialPositionAndLimits,10 depositFunds,11 addCallbackParticipantPut,12 addCallbackParticipantPutError,13 addCallbackParticipantPutBatch,14 addCallbackParticipantPutBatchError,15 addCallbackPartiesGet,16 addCallbackPartiesPut,17 addCallbackPartiesPutError,18 addCallbackQuotes,19 addCallbackTransferPost,20 addCallbackTransferPut,21 addCallbackTransferError,22 setEmailNetDebitCapAdjustment,23 setEmailSettlementTransferPositionChange,24 setEmailNetDebitCapThresholdBreach,25} = require('../../src/onboarding/onboarding');26describe('Onboarding', () => {27 describe('sendRequest', () => {28 it('should correctly format an onboarding request given an args array', () => {29 // Arrange30 const requestUrl = 'local.host';31 const requestData = {32 method: 'POST',33 headers: {},34 body: JSON.stringify({}),35 redirect: 'follow',36 };37 const request = [requestUrl, requestData];38 const expected = [requestUrl, { ...requestData, signal: new AbortController().signal }];39 const timeout = 30000;40 const jestFetch = jest.fn();41 // Act42 sendRequest(request, timeout, jestFetch);43 // Assert44 expect(jestFetch).toBeCalledWith(...expected);45 });46 });47 describe('settlementIdFromHubAccounts', () => {48 it('should return a settlementId given a currency and an array of hub accounts', () => {49 // Arrange50 const currency = 'XOF';51 const hubAccounts = [52 {53 id: 7,54 ledgerAccountType: 'POSITION',55 currency: 'XOF',56 isActive: 1,57 value: 277.1234,58 reservedValue: 0,59 changedDate: '2020-06-26T04:06:22.000Z',60 },61 {62 id: 8,63 ledgerAccountType: 'SETTLEMENT',64 currency: 'XOF',65 isActive: 1,66 value: -818010,67 reservedValue: 0,68 changedDate: '2020-06-25T16:42:46.000Z',69 },70 ];71 const expected = 8;72 // Act73 const actual = settlementIdFromHubAccounts(hubAccounts, currency);74 // Assert75 expect(actual).toEqual(expected);76 });77 });78 describe('createHubAccount', () => {79 it('should return args to create an account on the hub', () => {80 // Arrange81 const authToken = '4324sdfsfsdf2fsdffsdfs3';82 const hostCentralLedger = 'http://localhost';83 const fspiopSource = 'hub_operator';84 const type = 'HUB_MULTILATERAL_SETTLEMENT';85 const currency = 'XOF';86 const headersMap = new Map();87 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');88 headersMap.set('Content-Type', 'application/json');89 headersMap.set('FSPIOP-Source', 'hub_operator');90 const headers = new Headers(headersMap);91 const body = JSON.stringify({92 type: 'HUB_MULTILATERAL_SETTLEMENT',93 currency: 'XOF',94 });95 const expected = [96 'http://localhost/participants/Hub/accounts',97 {98 method: 'POST',99 headers,100 redirect: 'follow',101 body,102 },103 ];104 // Act105 const actual = createHubAccount({106 type,107 currency,108 authToken,109 hostCentralLedger,110 fspiopSource,111 });112 // Assert113 expect(actual).toEqual(expected);114 });115 });116 describe('getDfspAccounts', () => {117 it('should return args to get a DFSP\'s accounts on the hub', () => {118 // Arrange119 const dfspName = 'payerfsp';120 const authToken = '4324sdfsfsdf2fsdffsdfs3';121 const hostCentralLedger = 'http://localhost';122 const fspiopSource = 'hub_operator';123 const headersMap = new Map();124 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');125 headersMap.set('Content-Type', 'application/json');126 headersMap.set('FSPIOP-Source', 'hub_operator');127 const headers = new Headers(headersMap);128 const expected = [129 'http://localhost/participants/payerfsp/accounts',130 {131 method: 'GET',132 headers,133 redirect: 'follow',134 },135 ];136 // Act137 const actual = getDfspAccounts({138 dfspName,139 authToken,140 hostCentralLedger,141 fspiopSource,142 });143 // Assert144 expect(actual).toEqual(expected);145 });146 });147 describe('addDfsp', () => {148 it('should return args to add a DFSP to the hub', () => {149 // Arrange150 const dfspName = 'payerfsp';151 const dfspCurrency = 'XOF';152 const authToken = '4324sdfsfsdf2fsdffsdfs3';153 const hostCentralLedger = 'http://localhost';154 const fspiopSource = 'hub_operator';155 const headersMap = new Map();156 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');157 headersMap.set('Content-Type', 'application/json');158 headersMap.set('FSPIOP-Source', 'hub_operator');159 const headers = new Headers(headersMap);160 const body = JSON.stringify({161 name: 'payerfsp',162 currency: 'XOF',163 });164 const expected = [165 'http://localhost/participants',166 {167 method: 'POST',168 headers,169 body,170 redirect: 'follow',171 },172 ];173 // Act174 const actual = addDfsp({175 dfspName,176 dfspCurrency,177 authToken,178 hostCentralLedger,179 fspiopSource,180 });181 // Assert182 expect(actual).toEqual(expected);183 });184 });185 describe('addInitialPositionAndLimits', () => {186 it('should return args to add initial position and NDC for a given DFSP', () => {187 // Arrange188 const dfspName = 'payerfsp';189 const dfspCurrency = 'XOF';190 const netDebitCap = 10000;191 const initialPosition = 0;192 const authToken = '4324sdfsfsdf2fsdffsdfs3';193 const hostCentralLedger = 'http://localhost';194 const fspiopSource = 'hub_operator';195 const headersMap = new Map();196 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');197 headersMap.set('Content-Type', 'application/json');198 headersMap.set('FSPIOP-Source', 'hub_operator');199 const headers = new Headers(headersMap);200 const body = JSON.stringify({201 currency: 'XOF',202 limit: {203 type: 'NET_DEBIT_CAP',204 value: 10000,205 },206 initialPosition: 0,207 });208 const expected = [209 'http://localhost/participants/payerfsp/initialPositionAndLimits',210 {211 method: 'POST',212 headers,213 body,214 redirect: 'follow',215 },216 ];217 // Act218 const actual = addInitialPositionAndLimits({219 dfspName,220 dfspCurrency,221 netDebitCap,222 initialPosition,223 authToken,224 hostCentralLedger,225 fspiopSource,226 });227 // Assert228 expect(actual).toEqual(expected);229 });230 });231 describe('depositFunds', () => {232 it('should return args to deposit funds to a DFSP\'s account', () => {233 // Arrange234 const dfspName = 'payerfsp';235 const dfspCurrency = 'XOF';236 const authToken = '4324sdfsfsdf2fsdffsdfs3';237 const amount = 1000;238 const transferId = 'dee18631-6c40-438a-bdd0-67bac5e4e1c2';239 const settlementAccountId = 8;240 const hostCentralLedger = 'http://localhost';241 const fspiopSource = 'hub_operator';242 const headersMap = new Map();243 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');244 headersMap.set('Content-Type', 'application/json');245 headersMap.set('FSPIOP-Source', 'hub_operator');246 const headers = new Headers(headersMap);247 const body = JSON.stringify({248 transferId: 'dee18631-6c40-438a-bdd0-67bac5e4e1c2',249 externalReference: 'string',250 action: 'recordFundsIn',251 reason: 'string',252 amount: {253 amount: 1000,254 currency: 'XOF',255 },256 extensionList: {257 extension: [{258 key: 'string',259 value: 'string',260 }],261 },262 });263 const expected = [264 'http://localhost/participants/payerfsp/accounts/8',265 {266 method: 'POST',267 headers,268 body,269 redirect: 'follow',270 },271 ];272 // Act273 const actual = depositFunds({274 dfspName,275 dfspCurrency,276 amount,277 transferId,278 settlementAccountId,279 authToken,280 hostCentralLedger,281 fspiopSource,282 });283 // Assert284 expect(actual).toEqual(expected);285 });286 });287 describe('addCallbackParticipantPut', () => {288 it('should return args to add callback for participant PUT', () => {289 // Arrange290 const dfspName = 'payerfsp';291 const dfspCallbackUrl = 'http://dfsp';292 const authToken = '4324sdfsfsdf2fsdffsdfs3';293 const hostCentralLedger = 'http://localhost';294 const fspiopSource = 'hub_operator';295 const headersMap = new Map();296 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');297 headersMap.set('Content-Type', 'application/json');298 headersMap.set('FSPIOP-Source', 'hub_operator');299 const headers = new Headers(headersMap);300 const body = JSON.stringify({301 type: 'FSPIOP_CALLBACK_URL_PARTICIPANT_PUT',302 value: 'http://dfsp/participants/{{partyIdType}}/{{partyIdentifier}}',303 });304 const expected = [305 'http://localhost/participants/payerfsp/endpoints',306 {307 method: 'POST',308 headers,309 body,310 redirect: 'follow',311 },312 ];313 // Act314 const actual = addCallbackParticipantPut({315 dfspName,316 dfspCallbackUrl,317 authToken,318 hostCentralLedger,319 fspiopSource,320 });321 // Assert322 expect(actual).toEqual(expected);323 });324 });325 describe('addCallbackParticipantPutError', () => {326 it('should return args to add callback for participant PUT error', () => {327 // Arrange328 const dfspName = 'payerfsp';329 const dfspCallbackUrl = 'http://dfsp';330 const dfspPartyId = 'i_am_a_msisdn';331 const dfspPartyIdType = 'msisdn';332 const authToken = '4324sdfsfsdf2fsdffsdfs3';333 const hostCentralLedger = 'http://localhost';334 const fspiopSource = 'hub_operator';335 const headersMap = new Map();336 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');337 headersMap.set('Content-Type', 'application/json');338 headersMap.set('FSPIOP-Source', 'hub_operator');339 const headers = new Headers(headersMap);340 const body = JSON.stringify({341 type: 'FSPIOP_CALLBACK_URL_PARTICIPANT_PUT_ERROR',342 value: 'http://dfsp/participants/{{partyIdType}}/{{partyIdentifier}}/error',343 });344 const expected = [345 'http://localhost/participants/payerfsp/endpoints',346 {347 method: 'POST',348 headers,349 body,350 redirect: 'follow',351 },352 ];353 // Act354 const actual = addCallbackParticipantPutError({355 dfspName,356 dfspCallbackUrl,357 dfspPartyId,358 dfspPartyIdType,359 authToken,360 hostCentralLedger,361 fspiopSource,362 });363 // Assert364 expect(actual).toEqual(expected);365 });366 });367 describe('addCallbackParticipantPutBatch', () => {368 it('should return args to add callback for participant PUT batch', () => {369 // Arrange370 const dfspName = 'payerfsp';371 const dfspCallbackUrl = 'http://dfsp';372 const authToken = '4324sdfsfsdf2fsdffsdfs3';373 const hostCentralLedger = 'http://localhost';374 const fspiopSource = 'hub_operator';375 const headersMap = new Map();376 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');377 headersMap.set('Content-Type', 'application/json');378 headersMap.set('FSPIOP-Source', 'hub_operator');379 const headers = new Headers(headersMap);380 const body = JSON.stringify({381 type: 'FSPIOP_CALLBACK_URL_PARTICIPANT_BATCH_PUT',382 value: 'http://dfsp/participants/{{requestId}}',383 });384 const expected = [385 'http://localhost/participants/payerfsp/endpoints',386 {387 method: 'POST',388 headers,389 body,390 redirect: 'follow',391 },392 ];393 // Act394 const actual = addCallbackParticipantPutBatch({395 dfspName,396 dfspCallbackUrl,397 authToken,398 hostCentralLedger,399 fspiopSource,400 });401 // Assert402 expect(actual).toEqual(expected);403 });404 });405 describe('addCallbackParticipantPutBatchError', () => {406 it('should return args to add callback for participant PUT batch error', () => {407 // Arrange408 const dfspName = 'payerfsp';409 const dfspCallbackUrl = 'http://dfsp';410 const authToken = '4324sdfsfsdf2fsdffsdfs3';411 const hostCentralLedger = 'http://localhost';412 const fspiopSource = 'hub_operator';413 const headersMap = new Map();414 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');415 headersMap.set('Content-Type', 'application/json');416 headersMap.set('FSPIOP-Source', 'hub_operator');417 const headers = new Headers(headersMap);418 const body = JSON.stringify({419 type: 'FSPIOP_CALLBACK_URL_PARTICIPANT_BATCH_PUT_ERROR',420 value: 'http://dfsp/participants/{{requestId}}/error',421 });422 const expected = [423 'http://localhost/participants/payerfsp/endpoints',424 {425 method: 'POST',426 headers,427 body,428 redirect: 'follow',429 },430 ];431 // Act432 const actual = addCallbackParticipantPutBatchError({433 dfspName,434 dfspCallbackUrl,435 authToken,436 hostCentralLedger,437 fspiopSource,438 });439 // Assert440 expect(actual).toEqual(expected);441 });442 });443 describe('addCallbackPartiesGet', () => {444 it('should return args to add callback for parties GET', () => {445 // Arrange446 const dfspName = 'payerfsp';447 const dfspCallbackUrl = 'http://dfsp';448 const authToken = '4324sdfsfsdf2fsdffsdfs3';449 const hostCentralLedger = 'http://localhost';450 const fspiopSource = 'hub_operator';451 const headersMap = new Map();452 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');453 headersMap.set('Content-Type', 'application/json');454 headersMap.set('FSPIOP-Source', 'hub_operator');455 const headers = new Headers(headersMap);456 const body = JSON.stringify({457 type: 'FSPIOP_CALLBACK_URL_PARTIES_GET',458 value: 'http://dfsp/parties/{{partyIdType}}/{{partyIdentifier}}',459 });460 const expected = [461 'http://localhost/participants/payerfsp/endpoints',462 {463 method: 'POST',464 headers,465 body,466 redirect: 'follow',467 },468 ];469 // Act470 const actual = addCallbackPartiesGet({471 dfspName,472 dfspCallbackUrl,473 authToken,474 hostCentralLedger,475 fspiopSource,476 });477 // Assert478 expect(actual).toEqual(expected);479 });480 });481 describe('addCallbackPartiesPut', () => {482 it('should return args to add callback for parties PUT', () => {483 // Arrange484 const dfspName = 'payerfsp';485 const dfspCallbackUrl = 'http://dfsp';486 const authToken = '4324sdfsfsdf2fsdffsdfs3';487 const hostCentralLedger = 'http://localhost';488 const fspiopSource = 'hub_operator';489 const headersMap = new Map();490 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');491 headersMap.set('Content-Type', 'application/json');492 headersMap.set('FSPIOP-Source', 'hub_operator');493 const headers = new Headers(headersMap);494 const body = JSON.stringify({495 type: 'FSPIOP_CALLBACK_URL_PARTIES_PUT',496 value: 'http://dfsp/parties/{{partyIdType}}/{{partyIdentifier}}',497 });498 const expected = [499 'http://localhost/participants/payerfsp/endpoints',500 {501 method: 'POST',502 headers,503 body,504 redirect: 'follow',505 },506 ];507 // Act508 const actual = addCallbackPartiesPut({509 dfspName,510 dfspCallbackUrl,511 authToken,512 hostCentralLedger,513 fspiopSource,514 });515 // Assert516 expect(actual).toEqual(expected);517 });518 });519 describe('addCallbackPartiesPutError', () => {520 it('should return args to add callback for parties PUT error', () => {521 // Arrange522 const dfspName = 'payerfsp';523 const dfspCallbackUrl = 'http://dfsp';524 const authToken = '4324sdfsfsdf2fsdffsdfs3';525 const hostCentralLedger = 'http://localhost';526 const fspiopSource = 'hub_operator';527 const headersMap = new Map();528 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');529 headersMap.set('Content-Type', 'application/json');530 headersMap.set('FSPIOP-Source', 'hub_operator');531 const headers = new Headers(headersMap);532 const body = JSON.stringify({533 type: 'FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR',534 value: 'http://dfsp/parties/{{partyIdType}}/{{partyIdentifier}}/error',535 });536 const expected = [537 'http://localhost/participants/payerfsp/endpoints',538 {539 method: 'POST',540 headers,541 body,542 redirect: 'follow',543 },544 ];545 // Act546 const actual = addCallbackPartiesPutError({547 dfspName,548 dfspCallbackUrl,549 authToken,550 hostCentralLedger,551 fspiopSource,552 });553 // Assert554 expect(actual).toEqual(expected);555 });556 });557 describe('addCallbackQuotes', () => {558 it('should return args to add callback for quotes', () => {559 // Arrange560 const dfspName = 'payerfsp';561 const dfspCallbackUrl = 'http://dfsp';562 const authToken = '4324sdfsfsdf2fsdffsdfs3';563 const hostCentralLedger = 'http://localhost';564 const fspiopSource = 'hub_operator';565 const headersMap = new Map();566 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');567 headersMap.set('Content-Type', 'application/json');568 headersMap.set('FSPIOP-Source', 'hub_operator');569 const headers = new Headers(headersMap);570 const body = JSON.stringify({571 type: 'FSPIOP_CALLBACK_URL_QUOTES',572 value: 'http://dfsp',573 });574 const expected = [575 'http://localhost/participants/payerfsp/endpoints',576 {577 method: 'POST',578 headers,579 body,580 redirect: 'follow',581 },582 ];583 // Act584 const actual = addCallbackQuotes({585 dfspName,586 dfspCallbackUrl,587 authToken,588 hostCentralLedger,589 fspiopSource,590 });591 // Assert592 expect(actual).toEqual(expected);593 });594 });595 describe('addCallbackTransferPost', () => {596 it('should return args to add callback for transfer POST', () => {597 // Arrange598 const dfspName = 'payerfsp';599 const dfspCallbackUrl = 'http://dfsp';600 const authToken = '4324sdfsfsdf2fsdffsdfs3';601 const hostCentralLedger = 'http://localhost';602 const fspiopSource = 'hub_operator';603 const headersMap = new Map();604 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');605 headersMap.set('Content-Type', 'application/json');606 headersMap.set('FSPIOP-Source', 'hub_operator');607 const headers = new Headers(headersMap);608 const body = JSON.stringify({609 type: 'FSPIOP_CALLBACK_URL_TRANSFER_POST',610 value: 'http://dfsp/transfers',611 });612 const expected = [613 'http://localhost/participants/payerfsp/endpoints',614 {615 method: 'POST',616 headers,617 body,618 redirect: 'follow',619 },620 ];621 // Act622 const actual = addCallbackTransferPost({623 dfspName,624 dfspCallbackUrl,625 authToken,626 hostCentralLedger,627 fspiopSource,628 });629 // Assert630 expect(actual).toEqual(expected);631 });632 });633 describe('addCallbackTransferPut', () => {634 it('should return args to add callback for transfer PUT', () => {635 // Arrange636 const dfspName = 'payerfsp';637 const dfspCallbackUrl = 'http://dfsp';638 const authToken = '4324sdfsfsdf2fsdffsdfs3';639 const hostCentralLedger = 'http://localhost';640 const fspiopSource = 'hub_operator';641 const headersMap = new Map();642 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');643 headersMap.set('Content-Type', 'application/json');644 headersMap.set('FSPIOP-Source', 'hub_operator');645 const headers = new Headers(headersMap);646 const body = JSON.stringify({647 type: 'FSPIOP_CALLBACK_URL_TRANSFER_PUT',648 value: 'http://dfsp/transfers/{{transferId}}',649 });650 const expected = [651 'http://localhost/participants/payerfsp/endpoints',652 {653 method: 'POST',654 headers,655 body,656 redirect: 'follow',657 },658 ];659 // Act660 const actual = addCallbackTransferPut({661 dfspName,662 dfspCallbackUrl,663 authToken,664 hostCentralLedger,665 fspiopSource,666 });667 // Assert668 expect(actual).toEqual(expected);669 });670 });671 describe('addCallbackTransferError', () => {672 it('should return args to add callback for transfer error', () => {673 // Arrange674 const dfspName = 'payerfsp';675 const dfspCallbackUrl = 'http://dfsp';676 const authToken = '4324sdfsfsdf2fsdffsdfs3';677 const hostCentralLedger = 'http://localhost';678 const fspiopSource = 'hub_operator';679 const headersMap = new Map();680 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');681 headersMap.set('Content-Type', 'application/json');682 headersMap.set('FSPIOP-Source', 'hub_operator');683 const headers = new Headers(headersMap);684 const body = JSON.stringify({685 type: 'FSPIOP_CALLBACK_URL_TRANSFER_ERROR',686 value: 'http://dfsp/transfers/{{transferId}}/error',687 });688 const expected = [689 'http://localhost/participants/payerfsp/endpoints',690 {691 method: 'POST',692 headers,693 body,694 redirect: 'follow',695 },696 ];697 // Act698 const actual = addCallbackTransferError({699 dfspName,700 dfspCallbackUrl,701 authToken,702 hostCentralLedger,703 fspiopSource,704 });705 // Assert706 expect(actual).toEqual(expected);707 });708 });709 describe('setEmailNetDebitCapAdjustment', () => {710 it('should return args to set email for net debit cap adjustment', () => {711 // Arrange712 const dfspName = 'payerfsp';713 const email = 'manager@dfsp';714 const authToken = '4324sdfsfsdf2fsdffsdfs3';715 const hostCentralLedger = 'http://localhost';716 const fspiopSource = 'hub_operator';717 const headersMap = new Map();718 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');719 headersMap.set('Content-Type', 'application/json');720 headersMap.set('FSPIOP-Source', 'hub_operator');721 headersMap.set('Cache-Control', 'no-cache');722 const headers = new Headers(headersMap);723 const body = JSON.stringify({724 type: 'NET_DEBIT_CAP_ADJUSTMENT_EMAIL',725 value: 'manager@dfsp',726 });727 const expected = [728 'http://localhost/participants/payerfsp/endpoints',729 {730 method: 'POST',731 headers,732 body,733 redirect: 'follow',734 },735 ];736 // Act737 const actual = setEmailNetDebitCapAdjustment({738 dfspName,739 email,740 authToken,741 hostCentralLedger,742 fspiopSource,743 });744 // Assert745 expect(actual).toEqual(expected);746 });747 });748 describe('setEmailSettlementTransferPositionChange', () => {749 it('should return args to set email for settlement transfer position change', () => {750 // Arrange751 const dfspName = 'payerfsp';752 const email = 'manager@dfsp';753 const authToken = '4324sdfsfsdf2fsdffsdfs3';754 const hostCentralLedger = 'http://localhost';755 const fspiopSource = 'hub_operator';756 const headersMap = new Map();757 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');758 headersMap.set('Content-Type', 'application/json');759 headersMap.set('FSPIOP-Source', 'hub_operator');760 headersMap.set('Cache-Control', 'no-cache');761 const headers = new Headers(headersMap);762 const body = JSON.stringify({763 type: 'SETTLEMENT_TRANSFER_POSITION_CHANGE_EMAIL',764 value: 'manager@dfsp',765 });766 const expected = [767 'http://localhost/participants/payerfsp/endpoints',768 {769 method: 'POST',770 headers,771 body,772 redirect: 'follow',773 },774 ];775 // Act776 const actual = setEmailSettlementTransferPositionChange({777 dfspName,778 email,779 authToken,780 hostCentralLedger,781 fspiopSource,782 });783 // Assert784 expect(actual).toEqual(expected);785 });786 });787 describe('setEmailNetDebitCapThresholdBreach', () => {788 it('should return args to set email for net debit cap threshold breach', () => {789 // Arrange790 const dfspName = 'payerfsp';791 const email = 'manager@dfsp';792 const authToken = '4324sdfsfsdf2fsdffsdfs3';793 const hostCentralLedger = 'http://localhost';794 const fspiopSource = 'hub_operator';795 const headersMap = new Map();796 headersMap.set('Authorization', 'Bearer 4324sdfsfsdf2fsdffsdfs3');797 headersMap.set('Content-Type', 'application/json');798 headersMap.set('FSPIOP-Source', 'hub_operator');799 headersMap.set('Cache-Control', 'no-cache');800 const headers = new Headers(headersMap);801 const body = JSON.stringify({802 type: 'NET_DEBIT_CAP_THRESHOLD_BREACH_EMAIL',803 value: 'manager@dfsp',804 });805 const expected = [806 'http://localhost/participants/payerfsp/endpoints',807 {808 method: 'POST',809 headers,810 body,811 redirect: 'follow',812 },813 ];814 // Act815 const actual = setEmailNetDebitCapThresholdBreach({816 dfspName,817 email,818 authToken,819 hostCentralLedger,820 fspiopSource,821 });822 // Assert823 expect(actual).toEqual(expected);824 });825 });...

Full Screen

Full Screen

random_seed.ts

Source:random_seed.ts Github

copy

Full Screen

1/*2 * Copyright © 2020 Lisk Foundation3 *4 * See the LICENSE file at the top-level directory of this distribution5 * for licensing information.6 *7 * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,8 * no part of this software, including this file, may be copied, modified,9 * propagated, or distributed except according to the terms contained in the10 * LICENSE file.11 *12 * Removal or modification of this copyright notice is prohibited.13 */14import { BlockHeader } from '@liskhq/lisk-chain';15import { hash, intToBuffer } from '@liskhq/lisk-cryptography';16import * as Debug from 'debug';17import { Rounds } from './rounds';18import { FixedLengthArray, RandomSeed } from './types';19// eslint-disable-next-line new-cap20const debug = Debug('lisk:dpos:random_seed');21interface HeadersMap {22 [key: number]: BlockHeader;23}24const NUMBER_BYTE_SIZE = 4;25const RANDOM_SEED_BYTE_SIZE = 16;26const strippedHash = (data: Buffer): Buffer => {27 if (!(data instanceof Buffer)) {28 throw new Error('Hash input is not a valid type');29 }30 return hash(data).slice(0, RANDOM_SEED_BYTE_SIZE);31};32const bitwiseXOR = (bufferArray: Buffer[]): Buffer => {33 if (bufferArray.length === 1) {34 return bufferArray[0];35 }36 const bufferSizes = new Set(bufferArray.map(buffer => buffer.length));37 if (bufferSizes.size > 1) {38 throw new Error('All input for XOR should be same size');39 }40 const outputSize = [...bufferSizes][0];41 const result = Buffer.alloc(outputSize, 0);42 for (let i = 0; i < outputSize; i += 1) {43 // eslint-disable-next-line no-bitwise44 result[i] = bufferArray.map(b => b[i]).reduce((a, b) => a ^ b, 0);45 }46 return result;47};48const findPreviousHeaderOfDelegate = (49 header: BlockHeader,50 searchTillHeight: number,51 headersMap: HeadersMap,52): BlockHeader | undefined => {53 const { height, generatorPublicKey } = header;54 const searchTill = Math.max(searchTillHeight, 1);55 for (let i = height - 1; i >= searchTill; i -= 1) {56 if (headersMap[i].generatorPublicKey.equals(generatorPublicKey)) {57 return headersMap[i];58 }59 }60 return undefined;61};62const isValidSeedReveal = (seedReveal: Buffer, previousSeedReveal: Buffer): boolean =>63 strippedHash(seedReveal).equals(previousSeedReveal);64const selectSeedReveals = ({65 fromHeight,66 toHeight,67 headersMap,68 rounds,69}: {70 readonly fromHeight: number;71 readonly toHeight: number;72 readonly headersMap: HeadersMap;73 readonly rounds: Rounds;74}): Buffer[] => {75 const selected = [];76 for (let i = fromHeight; i >= toHeight; i -= 1) {77 const header = headersMap[i];78 const blockRound = rounds.calcRound(header.height);79 const lastForgedBlock = findPreviousHeaderOfDelegate(80 header,81 rounds.calcRoundStartHeight(blockRound - 1),82 headersMap,83 );84 // If delegate not forged any other block earlier in current and last round85 if (!lastForgedBlock) {86 continue;87 }88 // To validate seed reveal of any block in the last round89 // We have to check till second last round90 if (!isValidSeedReveal(header.asset.seedReveal, lastForgedBlock.asset.seedReveal)) {91 continue;92 }93 selected.push(header.asset.seedReveal);94 }95 return selected;96};97export const generateRandomSeeds = (98 round: number,99 rounds: Rounds,100 headers: ReadonlyArray<BlockHeader>,101): FixedLengthArray<RandomSeed, 2> => {102 // Middle range of a round to validate103 const middleThreshold = Math.floor(rounds.blocksPerRound / 2);104 const lastBlockHeight = headers[0].height;105 const startOfRound = rounds.calcRoundStartHeight(round);106 const middleOfRound = rounds.calcRoundMiddleHeight(round);107 const startOfLastRound = rounds.calcRoundStartHeight(round - 1);108 const endOfLastRound = rounds.calcRoundEndHeight(round - 1);109 const startOfSecondLastRound = rounds.calcRoundStartHeight(round - 2);110 if (lastBlockHeight < middleOfRound) {111 throw new Error(112 `Random seed can't be calculated earlier in a round. Wait till you pass middle of round. Current height: ${lastBlockHeight.toString()}`,113 );114 }115 if (round === 1) {116 debug('Returning static value because current round is 1');117 const randomSeed1ForFirstRound = strippedHash(118 intToBuffer(middleThreshold + 1, NUMBER_BYTE_SIZE),119 );120 const randomSeed2ForFirstRound = strippedHash(intToBuffer(0, NUMBER_BYTE_SIZE));121 return [randomSeed1ForFirstRound, randomSeed2ForFirstRound];122 }123 /**124 * We need to build a map for current and last two rounds. To previously forged125 * blocks we will use only current and last round. To validate seed reveal of126 * any block from last round we have to load second last round as well.127 */128 const headersMap = headers.reduce((acc: HeadersMap, header: BlockHeader): HeadersMap => {129 if (header.height >= startOfSecondLastRound && header.height <= middleOfRound) {130 acc[header.height] = header;131 }132 return acc;133 }, {});134 // From middle of current round to middle of last round135 debug('Fetching seed reveals for random seed 1', {136 fromHeight: startOfRound + middleThreshold,137 toHeight: startOfRound - middleThreshold,138 });139 const seedRevealsForRandomSeed1 = selectSeedReveals({140 fromHeight: startOfRound + middleThreshold,141 toHeight: startOfRound - middleThreshold,142 headersMap,143 rounds,144 });145 // From middle of current round to middle of last round146 debug('Fetching seed reveals for random seed 2', {147 fromHeight: endOfLastRound,148 toHeight: startOfLastRound,149 });150 const seedRevealsForRandomSeed2 = selectSeedReveals({151 fromHeight: endOfLastRound,152 toHeight: startOfLastRound,153 headersMap,154 rounds,155 });156 const randomSeed1 = bitwiseXOR([157 strippedHash(intToBuffer(startOfRound + middleThreshold, NUMBER_BYTE_SIZE)),158 ...seedRevealsForRandomSeed1,159 ]);160 const randomSeed2 = bitwiseXOR([161 strippedHash(intToBuffer(endOfLastRound, NUMBER_BYTE_SIZE)),162 ...seedRevealsForRandomSeed2,163 ]);164 return [randomSeed1, randomSeed2];...

Full Screen

Full Screen

fetchOptions.ts

Source:fetchOptions.ts Github

copy

Full Screen

1// import guid from 'simple-guid';2import md5 from 'md5';3import { RootState } from '../types/states';4type Options = {5 method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';6 credentials: 'include';7 headers: { [key: string]: string } | Headers;8 body?: string | FormData | Blob;9};10const wrapHeaders = (headersMap: { [key: string]: string }) =>11 'Headers' in window ? new Headers(headersMap) : headersMap;12/**13 * returns fetch options for basic api request with json response14 */15export const baseFetchOptions = (16 method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH',17 body?: FormData | Blob | object,18 customHeaders?: { [key: string]: string }19): Options => {20 let headersMap: { [key: string]: string } = {21 ...(customHeaders || {}),22 Accept: 'application/json',23 };24 if (method === 'GET') {25 return {26 method,27 credentials: 'include',28 headers: wrapHeaders(headersMap),29 };30 } else if (body instanceof FormData || body instanceof Blob) {31 return {32 method,33 credentials: 'include',34 headers: wrapHeaders(headersMap),35 body,36 };37 } else {38 headersMap = {39 ...headersMap,40 'Content-Type': 'application/json',41 };42 return {43 method,44 credentials: 'include',45 headers: wrapHeaders(headersMap),46 body: JSON.stringify(body || {}),47 };48 }49};50/**51 * returns fetch options with authentification headers52 */53const fetchOptions = (54 state: RootState,55 method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH',56 body?: FormData | Blob | object57): Options => {58 const { deviceId, authToken, userId } = state.auth.persist;59 if (!deviceId) {60 throw new Error('No device id');61 }62 let headersMap: { [key: string]: string } = {63 'X-Device-Id': deviceId,64 'X-Device-Type': 'web',65 // TODO: only required for auth methods66 'X-Timestamp-Hash': md5('time_covfefe_prefix=2020_' + deviceId),67 };68 if (authToken) {69 headersMap = {70 ...headersMap,71 'X-Auth-Token': authToken,72 };73 }74 if (userId) {75 headersMap = {76 ...headersMap,77 'X-User-Id': userId,78 };79 }80 return baseFetchOptions(method, body, headersMap);81};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var http = require('http');2var options = {3headers: {4}5};6var req = http.request(options, function (res) {7console.log('Status: ' + res.statusCode);8console.log('Headers: ' + JSON.stringify(res.headers));9res.setEncoding('utf8');10res.on('data', function (body) {11console.log('Body: ' + body);12});13});14req.on('error', function (e) {15console.log('problem with request: ' + e.message);16});17req.write('{"protocol": "http", "port": 3000, "stubs": [{"responses": [{"is": {"statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": "Hello World!"}}]}]}');18req.end();19var http = require('http');20var options = {21headers: {22}23};24var req = http.request(options, function (res) {25console.log('Status: ' + res.statusCode);26console.log('Headers: ' + JSON.stringify(res.headers));27res.setEncoding('utf8');28res.on('data', function (body) {29console.log('Body: ' + body);30});31});32req.on('error', function (e) {33console.log('problem with request: ' + e.message);34});35req.write('{"protocol": "http", "port": 3000, "stubs": [{"responses": [{"is": {"statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": "Hello World!"}}]}]}');36req.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var headersMap = require('mountebank').headersMap;2var mb = require('mountebank');3var imposter = {4 {5 {6 "is": {7 "headers": {8 },9 "body": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var headersMap = function (request, response, logger, next) {2 response.headers = {3 };4 next();5};6var proxy = function (request, response, logger, next) {7 response.proxy = {8 };9 next();10};11var stub = function (request, response, logger, next) {12 response.body = {13 };14 next();15};16var injection = function (request, response, logger, next) {17 response.injection = {18 javascript: 'response.body = "Hello World";'19 };20 next();21};22var predicates = function (request, response, logger, next) {23 {24 equals: {25 }26 }27 ];28 next();29};30var responses = function (request, response, logger, next) {31 {32 is: {33 headers: {34 },35 body: '{"message": "Hello World"}'36 }37 }38 ];39 next();40};41var stubs = function (request, response, logger, next) {42 {43 {44 is: {45 headers: {46 },47 body: '{"message": "Hello World"}'48 }49 }50 }51 ];52 next();53};54var is = function (request, response, logger, next) {55 response.is = {56 headers: {57 },58 body: '{"message": "Hello World"}'59 };60 next();61};62var addDecorators = function (request

Full Screen

Using AI Code Generation

copy

Full Screen

1var headersMap = require('mountebank').headersMap;2var headers = headersMap.create();3headers.addHeader('Access-Control-Allow-Origin', '*');4headers.addHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');5headers.addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');6headers.addHeader('Access-Control-Allow-Credentials', 'true');7module.exports = {8 {9 {10 "is": {11 "headers": headers.headers(),12 }13 }14 }15}

Full Screen

Using AI Code Generation

copy

Full Screen

1var headersMap = {2 'Location': {3 }4};5var imposter = {6 {7 {8 'is': {9 }10 }11 }12};13var mb = require('mountebank');14mb.create(imposter).then(function (result) {15});16var headersMap = {17 'Location': {18 }19};20var imposter = {21 {22 {23 'is': {24 }25 }26 }27};28var mb = require('mountebank');29mb.create(imposter).then(function (result) {30});31var headersMap = {32 'Location': {33 }34};35var imposter = {36 {37 {38 'is': {39 }40 }41 }42};43var mb = require('mountebank');44mb.create(imposter).then(function (result) {45});46var headersMap = {47 'Location': {48 }49};50var imposter = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var headersMap = {2 "Location": {3 }4};5var response = {6};7var imposter = {8 {9 {10 equals: {11 }12 }13 }14};15var mb = require('mountebank');16mb.create(imposter, function (error, imposter) {17 console.log("Imposter created at " + imposter.url);18});

Full Screen

Using AI Code Generation

copy

Full Screen

1var headers = imposter.headersMap();2var headers = imposter.headersMap();3console.log("Headers are: " + headers);4console.log("Headers are: " + headers);5if (headers["Content-Type"] == "application/json") {6 console.log("Content-Type is application/json");7 console.log("Content-Type is application/json");8 var body = imposter.body();9 console.log("Body is: " + body);10 console.log("Body is: " + body);11 var bodyJson = JSON.parse(body);12 console.log("Body JSON is: " + bodyJson);13 console.log("Body JSON is: " + bodyJson);14 var newBody = {15 };16 console.log("New Body is: " + newBody);17 console.log("New Body is: " + newBody);18 var newBodyString = JSON.stringify(newBody);19 console.log("New Body String is: " + newBodyString);20 console.log("New Body String is: " + newBodyString);21 imposter.body(newBodyString);22 console.log("New Body String is: " + newBodyString);23 console.log("New Body String is: " + newBodyString);24}25var headers = imposter.headersMap();26console.log("Headers are: " + headers);27if (headers["Content-Type"] == "application/json") {28 var body = imposter.body();29 console.log("Body is: " + body);30 var bodyJson = JSON.parse(body);31 console.log("Body JSON is: " + bodyJson);32 var newBody = {33 };34 console.log("New Body is: " + newBody);35 var newBodyString = JSON.stringify(newBody);36 console.log("New Body String is: " + newBodyString);37 imposter.body(newBodyString);38}

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run mountebank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful