Skip to content

Commit

Permalink
[tests] unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jun 18, 2024
1 parent 359419f commit aef7050
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/cmd/device-protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {

async _getProductId() {
if (this.productId) {
return;
return this.productId;
}

try {
Expand Down
51 changes: 43 additions & 8 deletions src/cmd/device-protection.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const DeviceProtectionCommands = require('./device-protection');
const FlashCommand = require('./flash');
const { expect, sinon } = require('../../test/setup');
// const fs = require('fs-extra');
// const { createProtectedModule } = require('binary-version-reader');

describe('DeviceProtectionCommands', () => {
let deviceProtectionCommands;
Expand Down Expand Up @@ -149,8 +146,7 @@ describe('DeviceProtectionCommands', () => {
await deviceProtectionCommands.enableProtection();

expect(deviceProtectionCommands._getDeviceProtection).to.have.been.calledOnce;
expect(deviceProtectionCommands._isDeviceProtectionActiveInProduct).to.have.been.calledOnce;
expect(deviceProtectionCommands._markAsDevelopmentDevice).to.have.been.calledOnce;
expect(deviceProtectionCommands._isDeviceProtectionActiveInProduct).to.not.have.been.called;
});

it('does not protect an open device if it is not in a product', async () => {
Expand Down Expand Up @@ -270,13 +266,52 @@ describe('DeviceProtectionCommands', () => {
});

describe('_isDeviceProtectionActiveInProduct', () => {
xit('should return true if device protection is active in the product', async () => {
it('should return true if device protection is active in the product', async () => {
sinon.stub(deviceProtectionCommands, '_getProductId').resolves();
deviceProtectionCommands.productId = '12345';
deviceProtectionCommands.api = {
getProduct: sinon.stub().resolves({
product: {
device_protection: 'active'
}
})
};

const res = await deviceProtectionCommands._isDeviceProtectionActiveInProduct();

expect(res).to.eql(true);

});

xit('should return false if device protection is not active in the product', async () => {
it('should return false if device protection is not active in the product', async () => {
sinon.stub(deviceProtectionCommands, '_getProductId').resolves();
deviceProtectionCommands.productId = '12345';
deviceProtectionCommands.api = {
getProduct: sinon.stub().resolves({
product: {
device_protection: ''
}
})
};

const res = await deviceProtectionCommands._isDeviceProtectionActiveInProduct();

expect(res).to.eql(false);
});

xit('should return false if the product ID is not available', async () => {
it('should return false if device protection is not available for this product', async () => {
sinon.stub(deviceProtectionCommands, '_getProductId').resolves();
deviceProtectionCommands.productId = '12345';
deviceProtectionCommands.api = {
getProduct: sinon.stub().resolves({
product: {
}
})
};

const res = await deviceProtectionCommands._isDeviceProtectionActiveInProduct();

expect(res).to.eql(false);
});
});

Expand Down

0 comments on commit aef7050

Please sign in to comment.