Skip to content

Commit

Permalink
Merge pull request #247 from shopware/add-feature-flag-info
Browse files Browse the repository at this point in the history
feat: add features data to InstanceMeta fixture
  • Loading branch information
pweyck authored Dec 20, 2024
2 parents ecdd714 + e6d4392 commit c9ae24d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
17 changes: 16 additions & 1 deletion src/fixtures/HelperFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ 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<string, boolean>;

export interface HelperFixtureTypes {
IdProvider: IdProvider;
SaaSInstanceSetup: () => Promise<void>,
InstanceMeta: {
version: string,
isSaaS: boolean,
features: FeaturesType,
},
}

Expand Down Expand Up @@ -61,11 +65,22 @@ export const test = base.extend<NonNullable<unknown>, 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<string, { major: boolean, active: boolean }>;
for (const k in data) {
features[k] = data[k].active;
}
}

use({
version: config.version,
isSaaS: await isSaaSInstance(context),
features,
});
},
{ scope: 'worker' },
Expand Down
11 changes: 11 additions & 0 deletions tests/Fixtures.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,6 +18,8 @@ test('All data fixtures', async ({
ProductData,
CategoryData,
PropertiesData,

InstanceMeta,
}) => {
const { id, uuid } = IdProvider.getIdPair();

Expand All @@ -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();
}
});

0 comments on commit c9ae24d

Please sign in to comment.