Skip to content

Commit

Permalink
add licenseInformation, add tier test and honor onlyWWW (#594)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominic Griesel <dominic.griesel@nabucasa.com>
  • Loading branch information
mcm1957 and AlCalzone authored Mar 5, 2024
1 parent 5078df7 commit ec79ddb
Showing 1 changed file with 57 additions and 5 deletions.
62 changes: 57 additions & 5 deletions src/tests/packageFiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ export function validatePackageFiles(adapterDir: string): void {
});

const packageContent = require(packageJsonPath);
const iopackContent = require(ioPackageJsonPath);

const requiredProperties = [
"name",
"version",
"description",
"author",
"license",
"main",
"repository",
"repository.type",
];
Expand Down Expand Up @@ -126,6 +126,12 @@ export function validatePackageFiles(adapterDir: string): void {
);
});

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");
});
Expand Down Expand Up @@ -164,7 +170,6 @@ export function validatePackageFiles(adapterDir: string): void {
"common.desc",
"common.icon",
"common.extIcon",
"common.license",
"common.type",
"common.authors",
"native",
Expand Down Expand Up @@ -204,6 +209,47 @@ 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.licenseInformation (preferred) or common.license (deprecated) must exist",
).to.not.be.undefined;
});
}

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);
});
}

// If the adapter has a configuration page, check that a supported admin UI is used
const hasNoConfigPage =
iopackContent.common.noConfig === true ||
Expand Down Expand Up @@ -245,9 +291,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,
);
}
});
});
});
Expand Down

0 comments on commit ec79ddb

Please sign in to comment.