From e6d4392ec0e504d3b61e609f6c79c3ec2fa7b793 Mon Sep 17 00:00:00 2001
From: Patrick Weyck
Date: Thu, 19 Dec 2024 17:06:00 +0100
Subject: [PATCH] feat: add features data to InstanceMeta fixture
---
package-lock.json | 6 ++++++
package.json | 1 +
src/fixtures/HelperFixtures.ts | 17 ++++++++++++++++-
tests/Fixtures.spec.ts | 11 +++++++++++
4 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/package-lock.json b/package-lock.json
index a28d8aca..4766d255 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,6 +13,7 @@
"@playwright/test": "^1.49.1",
"@shopware/api-client": "0.5.0",
"axe-html-reporter": "2.2.3",
+ "compare-versions": "^6.1.1",
"image-js": "0.35.5",
"uuid": "9.0.1"
},
@@ -1935,6 +1936,11 @@
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==",
"dev": true
},
+ "node_modules/compare-versions": {
+ "version": "6.1.1",
+ "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-6.1.1.tgz",
+ "integrity": "sha512-4hm4VPpIecmlg59CHXnRDnqGplJFrbLG4aFEl5vl6cK1u76ws3LLvX7ikFnTDl5vo39sjWD6AaDPYodJp/NNHg=="
+ },
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
diff --git a/package.json b/package.json
index 83ba06fa..138011ae 100644
--- a/package.json
+++ b/package.json
@@ -40,6 +40,7 @@
"@playwright/test": "^1.49.1",
"@shopware/api-client": "0.5.0",
"axe-html-reporter": "2.2.3",
+ "compare-versions": "^6.1.1",
"image-js": "0.35.5",
"uuid": "9.0.1"
},
diff --git a/src/fixtures/HelperFixtures.ts b/src/fixtures/HelperFixtures.ts
index 0ace5356..c148800c 100644
--- a/src/fixtures/HelperFixtures.ts
+++ b/src/fixtures/HelperFixtures.ts
@@ -4,6 +4,9 @@ import { isSaaSInstance } from '../services/ShopInfo';
import type { FixtureTypes } from '../types/FixtureTypes';
import { getCurrency, getLanguageData } from '../services/ShopwareDataHelpers';
import { AdminApiContext } from '../services/AdminApiContext';
+import { satisfies } from 'compare-versions';
+
+type FeaturesType = Record;
export interface HelperFixtureTypes {
IdProvider: IdProvider;
@@ -11,6 +14,7 @@ export interface HelperFixtureTypes {
InstanceMeta: {
version: string,
isSaaS: boolean,
+ features: FeaturesType,
},
}
@@ -61,11 +65,22 @@ export const test = base.extend, FixtureTypes>({
async ({ AdminApiContext: context }, use) => {
const response = await context.get('./_info/config');
expect(response.ok(), '/_info/config request failed').toBeTruthy();
-
const config = (await response.json()) as { version: string };
+
+ const features: FeaturesType = {};
+ if (satisfies(config.version, '>=6.6.0.0')) {
+ const featuresResponse = await context.get('./_action/feature-flag');
+ expect(featuresResponse.ok(), '/_action/feature-flag request failed').toBeTruthy();
+ const data = (await featuresResponse.json()) as Record;
+ for (const k in data) {
+ features[k] = data[k].active;
+ }
+ }
+
use({
version: config.version,
isSaaS: await isSaaSInstance(context),
+ features,
});
},
{ scope: 'worker' },
diff --git a/tests/Fixtures.spec.ts b/tests/Fixtures.spec.ts
index 42100dab..eccbd768 100644
--- a/tests/Fixtures.spec.ts
+++ b/tests/Fixtures.spec.ts
@@ -1,4 +1,7 @@
+/* eslint-disable playwright/no-conditional-in-test */
+/* eslint-disable playwright/no-conditional-expect */
import { test, expect } from '../src/index';
+import { satisfies } from 'compare-versions';
test('All data fixtures', async ({
AdminApiContext,
@@ -15,6 +18,8 @@ test('All data fixtures', async ({
ProductData,
CategoryData,
PropertiesData,
+
+ InstanceMeta,
}) => {
const { id, uuid } = IdProvider.getIdPair();
@@ -32,4 +37,10 @@ test('All data fixtures', async ({
expect(ProductData).toBeInstanceOf(Object);
expect(CategoryData).toBeInstanceOf(Object);
expect(PropertiesData).toBeInstanceOf(Object);
+
+ expect(InstanceMeta).toBeInstanceOf(Object);
+ if (satisfies(InstanceMeta.version, '>=6.6')) {
+ expect(InstanceMeta.features['V6_6_0_0']).toBeDefined();
+ expect(InstanceMeta.features['V6_6_0_0']).toBeTruthy();
+ }
});