Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/lib/services/data-encoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { page } from '$app/state';
import {
codecEndpoint,
includeCredentials,
overrideRemoteCodecConfiguration,
passAccessToken,
} from '$lib/stores/data-encoder-config';
import { getAccessToken, getIdToken } from '$lib/utilities/core-provider';
Expand All @@ -22,10 +23,15 @@ const mockGetIdToken = vi.mocked(getIdToken);
describe('Codec Server Requests for Decode and Encode', () => {
const payloads = { payloads: [{}] };

beforeEach(() => {
overrideRemoteCodecConfiguration.set(true);
});

afterEach(() => {
codecEndpoint.set(null);
passAccessToken.set(false);
includeCredentials.set(false);
overrideRemoteCodecConfiguration.set(false);
vi.clearAllMocks();
});

Expand Down Expand Up @@ -127,10 +133,15 @@ describe('Codec Server Requests for Decode and Encode', () => {
describe('codecPassAccessToken', () => {
const payloads = { payloads: [{}] };

beforeEach(() => {
overrideRemoteCodecConfiguration.set(true);
});

afterEach(() => {
codecEndpoint.set(null);
passAccessToken.set(false);
includeCredentials.set(false);
overrideRemoteCodecConfiguration.set(false);
vi.clearAllMocks();
});

Expand Down Expand Up @@ -227,10 +238,15 @@ describe('codecPassAccessToken', () => {
describe('codecIncludeCredentials', () => {
const payloads = { payloads: [{}] };

beforeEach(() => {
overrideRemoteCodecConfiguration.set(true);
});

afterEach(() => {
codecEndpoint.set(null);
passAccessToken.set(false);
includeCredentials.set(false);
overrideRemoteCodecConfiguration.set(false);
vi.clearAllMocks();
});

Expand Down
8 changes: 8 additions & 0 deletions src/lib/utilities/decode-payload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
codecEndpoint,
includeCredentials,
lastDataEncoderStatus,
overrideRemoteCodecConfiguration,
resetLastDataEncoderSuccess,
} from '../stores/data-encoder-config';

Expand Down Expand Up @@ -260,10 +261,15 @@ describe('parsePayloadAttributes', () => {
});

describe('decodeEventAttributes', () => {
beforeEach(() => {
overrideRemoteCodecConfiguration.set(true);
});

afterEach(() => {
resetLastDataEncoderSuccess();
codecEndpoint.set(null);
includeCredentials.set(false);
overrideRemoteCodecConfiguration.set(false);
vi.clearAllMocks();
});

Expand Down Expand Up @@ -375,6 +381,7 @@ describe('getEventAttributes', () => {
resetLastDataEncoderSuccess();
resetLastDataConverterSuccess();
codecEndpoint.set(null);
overrideRemoteCodecConfiguration.set(false);
});
it('Should convert a payload through data-converter and set the success status when the endpoint is set locally and the endpoint connects', async () => {
vi.stubGlobal('fetch', async () => {
Expand All @@ -384,6 +391,7 @@ describe('getEventAttributes', () => {
});

codecEndpoint.set('http://localhost:1337');
overrideRemoteCodecConfiguration.set(true);

const decodedPayload = await getEventAttributes(
parseWithBigInt(stringifyWithBigInt(workflowStartedHistoryEvent)),
Expand Down
6 changes: 3 additions & 3 deletions src/lib/utilities/get-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ describe('getCodec with configuration settings and local settings but override o
expect(credentials).toEqual(true);
});

it('should return codec endpoint from local setting with no settings', () => {
it('should return empty endpoint when no namespace-level codec is configured and override is off', () => {
codecEndpoint.set('http://mylocalserver.dev');
passAccessToken.set(true);
includeCredentials.set(false);
const settings = getSettings();
const endpoint = getCodecEndpoint(settings);
const token = getCodecPassAccessToken(settings);
const credentials = getCodecIncludeCredentials(settings);
expect(endpoint).toEqual('http://mylocalserver.dev');
expect(token).toEqual(true);
expect(endpoint).toEqual('');
expect(token).toEqual(false);
expect(credentials).toEqual(false);
});
});
Expand Down
16 changes: 7 additions & 9 deletions src/lib/utilities/get-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getCodecEndpoint = (
override = overrideRemoteCodecConfiguration,
): string => {
const overrideEndpoint = get(override) && get(endpoint);
return overrideEndpoint || settings?.codec?.endpoint || get(endpoint) || '';
return overrideEndpoint || settings?.codec?.endpoint || '';
};

export const getCodecPassAccessToken = (
Expand All @@ -24,10 +24,9 @@ export const getCodecPassAccessToken = (
override = overrideRemoteCodecConfiguration,
): boolean => {
const overrideEndpoint = get(override) && get(endpoint);
const nonOverrideOption = settings?.codec?.endpoint
? !!settings?.codec?.passAccessToken
: !!get(passToken);
return overrideEndpoint ? !!get(passToken) : nonOverrideOption;
return overrideEndpoint
? !!get(passToken)
: !!settings?.codec?.passAccessToken;
};

export const getCodecIncludeCredentials = (
Expand All @@ -37,8 +36,7 @@ export const getCodecIncludeCredentials = (
override = overrideRemoteCodecConfiguration,
): boolean => {
const overrideEndpoint = get(override) && get(endpoint);
const nonOverrideOption = settings?.codec?.endpoint
? !!settings?.codec?.includeCredentials
: !!get(includeCreds);
return overrideEndpoint ? !!get(includeCreds) : nonOverrideOption;
return overrideEndpoint
? !!get(includeCreds)
: !!settings?.codec?.includeCredentials;
};
Loading