From aef70500b632bda21d7d19f1cd7e3e06c1f061b3 Mon Sep 17 00:00:00 2001 From: keeramis Date: Tue, 18 Jun 2024 15:29:33 -0700 Subject: [PATCH] [tests] unit-tests --- src/cmd/device-protection.js | 2 +- src/cmd/device-protection.test.js | 51 ++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/cmd/device-protection.js b/src/cmd/device-protection.js index 5d936519c..487d833a2 100644 --- a/src/cmd/device-protection.js +++ b/src/cmd/device-protection.js @@ -312,7 +312,7 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase { async _getProductId() { if (this.productId) { - return; + return this.productId; } try { diff --git a/src/cmd/device-protection.test.js b/src/cmd/device-protection.test.js index 02c6051c7..31f094131 100644 --- a/src/cmd/device-protection.test.js +++ b/src/cmd/device-protection.test.js @@ -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; @@ -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 () => { @@ -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); }); });