Skip to content

Commit

Permalink
fix: "Others" id_type selection in doc v from smile links (#247)
Browse files Browse the repository at this point in the history
* fix: "Others" id_type selection in doc v from smile links

* format: run prettier

* tests: fix most failing tests

* fix: docv filters for others
  • Loading branch information
tamssokari authored Apr 10, 2024
1 parent 897a2f9 commit 0d35125
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
max-width: 100%;
min-height: 100%;
}
</style>
</head>

<body>
<script src="js/script.min.js"></script>

<script>
SmileIdentity({
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX3BhcmFtcyI6eyJ1c2VyX2lkIjoidXNlci1mZTIwY2JkYS1jMjJiLTRmZmUtOWRlZC05YjZhZGI2MDE1ZmIiLCJqb2JfaWQiOiJqb2ItNjYzY2VhNTUtZWIxYy00MjI2LWI1N2YtOGEwMTAwOTc4ZjViIiwiam9iX3R5cGUiOjF9LCJjYWxsYmFja191cmwiOiJodHRwczovL3dlYmhvb2suc2l0ZS9iZTM0YzkzZC1hOTFmLTQzZGItYWVmMi05MDZjNWNkOTVkNDciLCJpYXQiOjE2MzQyODE0MTAsImV4cCI6MTYzNTkxNTY4NH0.B4JaP4UWbNs38hV9nQ_9_Pnpos0fM3qu2nGG7Eymjs8',
id_types: [
{
country: 'AF',
id_type: '',
verification_method: 'doc_verification',
},
],
callback_url:
'https://portal.usesmileid.com/api/v2/007/postback/update_status',
environment: 'sandbox',
partner_details: {
name: 'Test Org',
logo_url: 'https://portal.usesmileid.com/favicon.ico',
partner_id: '007',
policy_url: 'https://usesmileid.com/privacy-policy',
theme_color: '#000',
},
onSuccess: () => {},
onClose: () => {},
});
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions packages/embed/cypress/tests/verification-method-selection.cy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,32 @@ describe('Verification Method Selection', () => {
.should('have.attr', 'src', 'http://localhost:8000/biometric-kyc.html');
});
});

describe('global document verification', () => {
beforeEach(() => {
cy.visit('/verification-method-global-document-verification');
});

it('it goes directly to the web embed', () => {
cy.getIFrameBody()
.find('#country option:selected')
.should('have.text', 'Afghanistan');

cy.getIFrameBody()
.find('#id_type option:selected')
.should('have.text', 'Others');

cy.getIFrameBody().find('#submitConfig').click();

cy.getIFrameBody()
.find(
'iframe[data-cy="smile-identity-hosted-web-integration-post-product-selection"]',
)
.should(
'have.attr',
'src',
'http://localhost:8000/doc-verification.html',
);
});
});
});
17 changes: 13 additions & 4 deletions packages/embed/src/js/doc-verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,22 @@ import { version as sdkVersion } from '../../package.json';
}

function loadIdTypeSelector(idTypes) {
const isSingleIdType = idTypes.length === 1;
const idTypeSelector = document.querySelector('#id-type-selector');

let combobox = document.querySelector('smileid-combobox[id="id_type"]');
if (!combobox) {
combobox = document.createElement('smileid-combobox');
combobox.setAttribute('id', 'id_type');
}

combobox.innerHTML = `
<smileid-combobox-trigger type="button" label="Select Document">
<smileid-combobox-trigger
${isSingleIdType ? 'disabled' : ''}
${isSingleIdType ? `value="${idTypes[0].name}"` : ''}
label="Select Document"
type="button"
>
</smileid-combobox-trigger>
<smileid-combobox-listbox empty-label="No country found">
Expand Down Expand Up @@ -200,14 +207,15 @@ import { version as sdkVersion } from '../../package.json';
).id_types;

if (config.id_selection) {
return countryIdTypes.filter((idType) => {
const result = countryIdTypes.filter((idType) => {
return config.id_selection[countryCode].find((validIdType) => {
if (validIdType.toLowerCase() === 'others') {
if (validIdType === '' || validIdType.toLowerCase() === 'others') {
return !idType.code;
}
return validIdType === idType.code;
});
});
return result;
}

return countryIdTypes;
Expand Down Expand Up @@ -305,6 +313,7 @@ import { version as sdkVersion } from '../../package.json';
const idTypes = config.id_selection[selectedCountry];
if (idTypes.length === 1 || typeof idTypes === 'string') {
id_info.id_type = Array.isArray(idTypes) ? idTypes[0] : idTypes;

const documentCaptureConfig = constraints
.find((entry) => entry.country.code === selectedCountry)
.id_types.find((entry) => entry.code === id_info.id_type);
Expand Down Expand Up @@ -342,7 +351,7 @@ import { version as sdkVersion } from '../../package.json';
};
});

if (!id_info || !id_info.id_type) {
if (!id_info || id_info.id_type === undefined) {
const selectCountry = SelectIDType.querySelector('#country');
const hostedWebConfigForm = document.querySelector(
'form[name="hosted-web-config"]',
Expand Down

0 comments on commit 0d35125

Please sign in to comment.