|
| 1 | +// / <reference types="cypress" /> |
| 2 | +import { SocketIO, Server } from 'mock-socket'; |
| 3 | +import { encrypt } from '../../ui/lib/helpers'; |
| 4 | + |
| 5 | +const fakeURL = 'http://internal.dev:8888'; |
| 6 | +const fakePassword = 'TpL4apWPbpRgfF4iEue8W4Fu11r60tRf'; |
| 7 | + |
| 8 | +const scannerCompany = { |
| 9 | + detail: `{"channelId":"UWNd14u","challenge":"jofzk2syMF","password":"${fakePassword}","requestedCredentials":["Address","PersonalData","ContactDetails"],"shareWith":"company","url":"${fakeURL}"}` |
| 10 | +}; |
| 11 | +const scannerBank = { |
| 12 | + detail: `{"channelId":"escaEww","challenge":"cyZChxcW4R","password":"${fakePassword}","requestedCredentials":["Address","PersonalData","ContactDetails","Company"],"shareWith":"bank","url":"${fakeURL}"}` |
| 13 | +}; |
| 14 | +const scannerInsurance = { |
| 15 | + detail: `{"channelId":"qkTLSIC","challenge":"J8K6qDEcjW","password":"${fakePassword}","requestedCredentials":["Address","PersonalData","ContactDetails","Company","BankAccount"],"shareWith":"insurance","url":"${fakeURL}"}` |
| 16 | +}; |
| 17 | + |
| 18 | +context('Bank Flow', () => { |
| 19 | + beforeEach(() => { |
| 20 | + cy.fixture('bank').as('bankFixture'); |
| 21 | + cy.fixture('account').as('accountFixture'); |
| 22 | + |
| 23 | + cy.get('@accountFixture').then((accountFixture) => { |
| 24 | + cy.window().then((win) => { |
| 25 | + Object.entries(accountFixture.localStorage).map((entry) => win.localStorage.setItem(entry[0], entry[1])); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + cy.visit('http://localhost:3001'); |
| 30 | + |
| 31 | + cy.get('@bankFixture').then((bankFixture) => { |
| 32 | + const mockServer = new Server(fakeURL); |
| 33 | + mockServer.on('connection', (socket) => { |
| 34 | + // eslint-disable-next-line no-console |
| 35 | + console.debug('mock connection established'); |
| 36 | + |
| 37 | + socket.on('verifiablePresentation', (message) => { |
| 38 | + // eslint-disable-next-line no-console |
| 39 | + console.debug('verifiablePresentation', JSON.stringify(message)); |
| 40 | + setTimeout(() => { |
| 41 | + if (message.channelId === 'UWNd14u') { |
| 42 | + mockServer.emit( |
| 43 | + 'createCredential', |
| 44 | + JSON.stringify({ |
| 45 | + schemaName: 'Company', |
| 46 | + data: encrypt(fakePassword, JSON.stringify(bankFixture.companyData)), |
| 47 | + url: fakeURL |
| 48 | + }) |
| 49 | + ); |
| 50 | + } |
| 51 | + if (message.channelId === 'escaEww') { |
| 52 | + mockServer.emit( |
| 53 | + 'createCredential', |
| 54 | + JSON.stringify({ |
| 55 | + schemaName: 'BankAccount', |
| 56 | + data: encrypt(fakePassword, JSON.stringify(bankFixture.bankData)), |
| 57 | + url: fakeURL |
| 58 | + }) |
| 59 | + ); |
| 60 | + } |
| 61 | + if (message.channelId === 'qkTLSIC') { |
| 62 | + mockServer.emit( |
| 63 | + 'createCredential', |
| 64 | + JSON.stringify({ |
| 65 | + schemaName: 'Insurance', |
| 66 | + data: encrypt(fakePassword, JSON.stringify(bankFixture.insuranceData)), |
| 67 | + url: fakeURL |
| 68 | + }) |
| 69 | + ); |
| 70 | + } |
| 71 | + }, 1000); |
| 72 | + }); |
| 73 | + |
| 74 | + socket.on('createCredential', (message) => { |
| 75 | + // eslint-disable-next-line no-console |
| 76 | + console.debug('createCredential', JSON.stringify(message)); |
| 77 | + }); |
| 78 | + |
| 79 | + socket.on('error', (error) => { |
| 80 | + console.error(error); |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | + cy.wrap(mockServer).as('mockServer'); |
| 85 | + cy.window().then((win) => { |
| 86 | + // eslint-disable-next-line no-param-reassign |
| 87 | + win.io = SocketIO; |
| 88 | + }); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + it('flow', () => { |
| 93 | + cy.contains('Scan Code').click(); |
| 94 | + cy.window().then((win) => { |
| 95 | + win.handleScannerData(scannerCompany); |
| 96 | + }); |
| 97 | + cy.contains('Share credential').click(); |
| 98 | + |
| 99 | + cy.get('.list:contains("My Identity")'); |
| 100 | + |
| 101 | + cy.contains('Accept certificate?', { timeout: 10000 }); |
| 102 | + cy.contains('Business Details'); |
| 103 | + cy.get('button:contains("Accept certificate")').click(); |
| 104 | + |
| 105 | + cy.get('.list:contains("Business Details")', { timeout: 10000 }).click(); |
| 106 | + |
| 107 | + cy.get('@bankFixture').then((bankFixture) => { |
| 108 | + bankFixture.companyDataFieldsToTest.map((field) => cy.contains(bankFixture.companyData[field])); |
| 109 | + }); |
| 110 | + |
| 111 | + cy.get('img[src="chevron-left.svg"]').click(); |
| 112 | + |
| 113 | + cy.window().then((win) => { |
| 114 | + win.handleScannerData(scannerBank); |
| 115 | + }); |
| 116 | + cy.contains('Share credential').click(); |
| 117 | + |
| 118 | + cy.contains('Accept certificate?', { timeout: 10000 }); |
| 119 | + cy.contains('Bank Details'); |
| 120 | + cy.get('button:contains("Accept certificate")').click(); |
| 121 | + |
| 122 | + // TODO: check document |
| 123 | + |
| 124 | + cy.window().then((win) => { |
| 125 | + win.handleScannerData(scannerInsurance); |
| 126 | + }); |
| 127 | + cy.contains('Share credential').click(); |
| 128 | + |
| 129 | + cy.contains('Accept certificate?', { timeout: 10000 }); |
| 130 | + cy.contains('Liability Insurance'); |
| 131 | + cy.get('button:contains("Accept certificate")').click(); |
| 132 | + |
| 133 | + // TODO: check document |
| 134 | + }); |
| 135 | + |
| 136 | + afterEach(() => { |
| 137 | + cy.get('@mockServer').then((mockServer) => mockServer.stop()); |
| 138 | + }); |
| 139 | +}); |
0 commit comments