From 7d7b2cee3c47bedb5e2cba07f33ca2c0b35856fb Mon Sep 17 00:00:00 2001 From: Martin M Date: Sat, 24 Feb 2024 22:17:07 +0100 Subject: [PATCH 1/3] add licenseInformation and tier tests --- src/tests/packageFiles/index.ts | 47 +++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/tests/packageFiles/index.ts b/src/tests/packageFiles/index.ts index ec9d77fc..d7f6ce95 100644 --- a/src/tests/packageFiles/index.ts +++ b/src/tests/packageFiles/index.ts @@ -89,6 +89,7 @@ export function validatePackageFiles(adapterDir: string): void { }); const packageContent = require(packageJsonPath); + const iopackContent = require(ioPackageJsonPath); const requiredProperties = [ "name", @@ -96,7 +97,6 @@ export function validatePackageFiles(adapterDir: string): void { "description", "author", "license", - "main", "repository", "repository.type", ]; @@ -126,6 +126,12 @@ export function validatePackageFiles(adapterDir: string): void { ); }); + it(`property main is defined for non onlyWWW adapters`, () => { + if (!iopackContent.common.onlyWWW){ + expect(packageContent.main).to.not.be.undefined; + } + }); + it(`The repository type is "git"`, () => { expect(packageContent.repository.type).to.equal("git"); }); @@ -164,7 +170,6 @@ export function validatePackageFiles(adapterDir: string): void { "common.desc", "common.icon", "common.extIcon", - "common.license", "common.type", "common.authors", "native", @@ -204,6 +209,32 @@ export function validatePackageFiles(adapterDir: string): void { expect(Object.keys(news).length).to.be.at.most(20); }); + if (iopackContent.common.licenseInformation) { + it(`if common.licenseInformation exists, it is an object with required properties`, () => { + expect(iopackContent.common.licenseInformation).to.be.an("object"); + expect(iopackContent.common.licenseInformation.type).to.be.oneOf(['free', 'commercial', 'paid', 'limited']); + + if (iopackContent.common.licenseInformation.type !== "free") { + expect(iopackContent.common.licenseInformation.link, 'License link is missing').to.not.be.undefined; + } + }); + + it(`common.license should not exist together with common.licenseInformation`, () => { + expect(iopackContent.common.license, 'common.license must be removed').to.be.undefined; + }); + } else { + it(`common.license must exist without common.licenseInformation`, () => { + expect(iopackContent.common.license, 'common.license or common.licenseInformation must exit').to.not.be.undefined; + }); + } + + if (iopackContent.common.tier) { + it(`common.tier must be 1, 2 or 3`, () => { + expect(iopackContent.common.tier).to.be.at.least(1); + expect(iopackContent.common.tier).to.be.at.most(3); + }); + } + // If the adapter has a configuration page, check that a supported admin UI is used const hasNoConfigPage = iopackContent.common.noConfig === true || @@ -245,9 +276,15 @@ export function validatePackageFiles(adapterDir: string): void { }); it("The license matches", () => { - expect(iopackContent.common.license).to.equal( - packageContent.license, - ); + if (iopackContent.common.licenseInformation) { + expect(iopackContent.common.licenseInformation.license).to.equal( + packageContent.license, + ); + } else { + expect(iopackContent.common.license).to.equal( + packageContent.license, + ); + } }); }); }); From cc7d561982b3edb1132a113def93a995467713e1 Mon Sep 17 00:00:00 2001 From: Martin M Date: Tue, 27 Feb 2024 15:02:12 +0100 Subject: [PATCH 2/3] fixes after review --- src/tests/packageFiles/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tests/packageFiles/index.ts b/src/tests/packageFiles/index.ts index d7f6ce95..a72f2be6 100644 --- a/src/tests/packageFiles/index.ts +++ b/src/tests/packageFiles/index.ts @@ -126,12 +126,12 @@ export function validatePackageFiles(adapterDir: string): void { ); }); - it(`property main is defined for non onlyWWW adapters`, () => { - if (!iopackContent.common.onlyWWW){ + if (!iopackContent.common.onlyWWW){ + it(`property main is defined for non onlyWWW adapters`, () => { expect(packageContent.main).to.not.be.undefined; - } - }); - + }); + }; + it(`The repository type is "git"`, () => { expect(packageContent.repository.type).to.equal("git"); }); @@ -224,11 +224,11 @@ export function validatePackageFiles(adapterDir: string): void { }); } else { it(`common.license must exist without common.licenseInformation`, () => { - expect(iopackContent.common.license, 'common.license or common.licenseInformation must exit').to.not.be.undefined; + expect(iopackContent.common.license, 'common.licenseInformation (preferred) or common.license (deprecated) must exist').to.not.be.undefined; }); } - if (iopackContent.common.tier) { + if (iopackContent.common.tier != undefined) { it(`common.tier must be 1, 2 or 3`, () => { expect(iopackContent.common.tier).to.be.at.least(1); expect(iopackContent.common.tier).to.be.at.most(3); From 3f65dcf242a70e98f2a10d45cebf121b493cb2e1 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 5 Mar 2024 09:53:06 +0100 Subject: [PATCH 3/3] auto-format code --- src/tests/packageFiles/index.ts | 43 ++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/tests/packageFiles/index.ts b/src/tests/packageFiles/index.ts index a72f2be6..8d754667 100644 --- a/src/tests/packageFiles/index.ts +++ b/src/tests/packageFiles/index.ts @@ -126,12 +126,12 @@ export function validatePackageFiles(adapterDir: string): void { ); }); - if (!iopackContent.common.onlyWWW){ + if (!iopackContent.common.onlyWWW) { it(`property main is defined for non onlyWWW adapters`, () => { expect(packageContent.main).to.not.be.undefined; }); - }; - + } + it(`The repository type is "git"`, () => { expect(packageContent.repository.type).to.equal("git"); }); @@ -211,21 +211,36 @@ export function validatePackageFiles(adapterDir: string): void { if (iopackContent.common.licenseInformation) { it(`if common.licenseInformation exists, it is an object with required properties`, () => { - expect(iopackContent.common.licenseInformation).to.be.an("object"); - expect(iopackContent.common.licenseInformation.type).to.be.oneOf(['free', 'commercial', 'paid', 'limited']); + expect(iopackContent.common.licenseInformation).to.be.an( + "object", + ); + expect( + iopackContent.common.licenseInformation.type, + ).to.be.oneOf(["free", "commercial", "paid", "limited"]); - if (iopackContent.common.licenseInformation.type !== "free") { - expect(iopackContent.common.licenseInformation.link, 'License link is missing').to.not.be.undefined; + if ( + iopackContent.common.licenseInformation.type !== "free" + ) { + expect( + iopackContent.common.licenseInformation.link, + "License link is missing", + ).to.not.be.undefined; } }); it(`common.license should not exist together with common.licenseInformation`, () => { - expect(iopackContent.common.license, 'common.license must be removed').to.be.undefined; + expect( + iopackContent.common.license, + "common.license must be removed", + ).to.be.undefined; }); } else { it(`common.license must exist without common.licenseInformation`, () => { - expect(iopackContent.common.license, 'common.licenseInformation (preferred) or common.license (deprecated) must exist').to.not.be.undefined; - }); + expect( + iopackContent.common.license, + "common.licenseInformation (preferred) or common.license (deprecated) must exist", + ).to.not.be.undefined; + }); } if (iopackContent.common.tier != undefined) { @@ -234,7 +249,7 @@ export function validatePackageFiles(adapterDir: string): void { expect(iopackContent.common.tier).to.be.at.most(3); }); } - + // If the adapter has a configuration page, check that a supported admin UI is used const hasNoConfigPage = iopackContent.common.noConfig === true || @@ -277,9 +292,9 @@ export function validatePackageFiles(adapterDir: string): void { it("The license matches", () => { if (iopackContent.common.licenseInformation) { - expect(iopackContent.common.licenseInformation.license).to.equal( - packageContent.license, - ); + expect( + iopackContent.common.licenseInformation.license, + ).to.equal(packageContent.license); } else { expect(iopackContent.common.license).to.equal( packageContent.license,