Skip to content

Commit

Permalink
Handle test ICCIDs. Do not error if test ICCIDs are present
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Nov 27, 2024
1 parent 60ead3d commit fb286eb
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/cmd/esim.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const PROVISIONING_FAILURE = 3;
const CTRL_REQUEST_APP_CUSTOM = 10;
const GET_AT_COMMAND_STATUS = 4;

const TEST_ICCIDs = ['89000123456789012341', '89000123456789012358'];

module.exports = class ESimCommands extends CLICommandBase {
constructor() { // TODO: Bring ui class
super();
Expand Down Expand Up @@ -156,11 +158,22 @@ module.exports = class ESimCommands extends CLICommandBase {
await processOutput();
return;
}
if (profileCmdResp.details.existingProfiles.length > 0) {
success = false;
provisionOutputLogs.push('Profiles already exist on the device');
await processOutput();
return;
const existingProfiles = profileCmdResp.details.existingProfiles;
if (existingProfiles.length > 0) {
// remove profiles with test ICCID from existingProfiles to verify
existingProfiles.forEach((profile, index) => {
const iccid = profile.split('[')[1].split(',')[0].trim();
if (TEST_ICCIDs.includes(iccid)) {
existingProfiles.splice(index, 1);
}
});

if (existingProfiles.length > 0) {
success = false;
provisionOutputLogs.push('Profiles already exist on the device');
await processOutput();
return;
}
}

// Get the next available profile list from availableProvisioningData
Expand Down Expand Up @@ -245,7 +258,11 @@ module.exports = class ESimCommands extends CLICommandBase {
};
const profilesOnDeviceAfterDownload = await this._listProfiles(port);
const iccidsOnDeviceAfterDownload = profilesOnDeviceAfterDownload.map((line) => line.split('[')[1].split(',')[0].trim());
const equal = _.isEqual(_.sortBy(iccidsOnDeviceAfterDownload), _.sortBy(expectedIccids));

// remove test ICCIDs from iccidsOnDeviceAfterDownload
const iccidsOnDeviceAfterDownloadFiltered = iccidsOnDeviceAfterDownload.filter((iccid) => !TEST_ICCIDs.includes(iccid));

const equal = _.isEqual(_.sortBy(iccidsOnDeviceAfterDownload), _.sortBy(iccidsOnDeviceAfterDownloadFiltered));

res.details.iccidsOnDevice = iccidsOnDeviceAfterDownload;
res.details.rawLogs.push(equal ? ['Profiles on device match the expected profiles'] :
Expand Down

0 comments on commit fb286eb

Please sign in to comment.