Skip to content

Commit

Permalink
chore: loosen some test assertions, fix e2e matcher (#933)
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
  • Loading branch information
toddbaert committed Jun 6, 2024
1 parent 0bf2df0 commit 8def607
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 137 deletions.
16 changes: 4 additions & 12 deletions libs/providers/flagd/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
services:
flagd:
build:
context: test-harness
dockerfile: flagd/Dockerfile
image: ghcr.io/open-feature/flagd-testbed:v0.5.4
ports:
- 8013:8013
flagd-unstable:
build:
context: test-harness
dockerfile: flagd/Dockerfile.unstable
image: ghcr.io/open-feature/flagd-testbed-unstable:v0.5.4
ports:
- 8014:8013
flagd-sync:
build:
context: test-harness
dockerfile: sync/Dockerfile
image: ghcr.io/open-feature/sync-testbed:v0.5.4
ports:
- 9090:9090
flagd-sync-unstable:
build:
context: test-harness
dockerfile: sync/Dockerfile.unstable
image: ghcr.io/open-feature/sync-testbed-unstable:v0.5.4
ports:
- 9091:9090
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const evaluateStringFlagWithContext: StepsDefinitionCallbackFunction = ({ given,
flagKey = key;
defaultValue = defaultVal;
});
and(/^a context containing a key "(.*)", with value "(.*)"$/, (key: string, value: string) => {
// the below has to match quotes strings ("str") and numbers (3) to test an error input
and(/^a context containing a key "(.*)", with value "?([^"]*)"?$/, (key: string, value: string) => {
evaluationContext[key] = value;
});
then(/^the returned value should be "(.*)"$/, async (expectedValue: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ describe('GoFeatureFlagProvider', () => {
const want = {
errorCode: ErrorCode.PROVIDER_NOT_READY,
flagKey: flagName,
reason: StandardResolutionReasons.UNKNOWN,
value: true,
variant: 'trueVariation',
reason: StandardResolutionReasons.ERROR,
value: false,
flagMetadata: {},
};
expect(res).toEqual(want);
expect(res).toEqual(expect.objectContaining(want));
});
it('unknown error codes should return GENERAL code', async () => {
const flagName = 'random-other-other-flag';
Expand All @@ -119,12 +118,11 @@ describe('GoFeatureFlagProvider', () => {
const want = {
errorCode: ErrorCode.GENERAL,
flagKey: flagName,
reason: StandardResolutionReasons.UNKNOWN,
value: true,
variant: 'trueVariation',
reason: StandardResolutionReasons.ERROR,
value: false,
flagMetadata: {},
};
expect(res).toEqual(want);
expect(res).toEqual(expect.objectContaining(want));
});
});
it('should throw an error if we fail in other network errors case', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ describe('LaunchDarklyClientProvider', () => {
});

const res = ofClient.getBooleanDetails(testFlagKey, false);
expect(res).toEqual({
flagKey: testFlagKey,
flagMetadata: {},
value: false,
reason: 'ERROR',
errorCode: 'TYPE_MISMATCH',
});
expect(res).toEqual(
expect.objectContaining({
flagKey: testFlagKey,
flagMetadata: {},
value: false,
reason: 'ERROR',
errorCode: 'TYPE_MISMATCH',
}),
);
});
});

Expand Down Expand Up @@ -193,13 +195,15 @@ describe('LaunchDarklyClientProvider', () => {
});

const res = ofClient.getNumberDetails(testFlagKey, 0);
expect(res).toEqual({
flagKey: testFlagKey,
flagMetadata: {},
value: 0,
reason: 'ERROR',
errorCode: 'TYPE_MISMATCH',
});
expect(res).toEqual(
expect.objectContaining({
flagKey: testFlagKey,
flagMetadata: {},
value: 0,
reason: 'ERROR',
errorCode: 'TYPE_MISMATCH',
}),
);
});
});

Expand Down Expand Up @@ -247,13 +251,15 @@ describe('LaunchDarklyClientProvider', () => {
});

const res = ofClient.getObjectDetails(testFlagKey, {});
expect(res).toEqual({
flagKey: testFlagKey,
flagMetadata: {},
value: {},
reason: 'ERROR',
errorCode: 'TYPE_MISMATCH',
});
expect(res).toEqual(
expect.objectContaining({
flagKey: testFlagKey,
flagMetadata: {},
value: {},
reason: 'ERROR',
errorCode: 'TYPE_MISMATCH',
}),
);
});
});

Expand Down Expand Up @@ -301,13 +307,15 @@ describe('LaunchDarklyClientProvider', () => {
});

const res = ofClient.getStringDetails(testFlagKey, 'default');
expect(res).toEqual({
flagKey: testFlagKey,
flagMetadata: {},
value: 'default',
reason: 'ERROR',
errorCode: 'TYPE_MISMATCH',
});
expect(res).toEqual(
expect.objectContaining({
flagKey: testFlagKey,
flagMetadata: {},
value: 'default',
reason: 'ERROR',
errorCode: 'TYPE_MISMATCH',
}),
);
});
});

Expand All @@ -328,14 +336,14 @@ describe('LaunchDarklyClientProvider', () => {
});

const res = ofClient.getObjectDetails(testFlagKey, {});
expect(res).toEqual({
flagKey: testFlagKey,
flagMetadata: {},
value: { yes: 'no' },
reason: 'ERROR',
errorCode: ofError,
variant: undefined,
});
expect(res).toEqual(
expect.objectContaining({
flagKey: testFlagKey,
flagMetadata: {},
reason: 'ERROR',
errorCode: ofError,
}),
);
});

it('includes the variant', async () => {
Expand Down
111 changes: 32 additions & 79 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"eslint-plugin-prettier": "^5.0.1",
"fetch-mock-jest": "^1.5.1",
"jest": "^29.4.1",
"jest-cucumber": "4.2.0",
"jest-cucumber": "^4.4.0",
"jest-environment-jsdom": "^29.4.1",
"jest-fetch-mock": "^3.0.3",
"jest-websocket-mock": "^2.4.0",
Expand Down

0 comments on commit 8def607

Please sign in to comment.