Skip to content

Commit

Permalink
fix(SdkOptions): Fix SdkOptions to return cssBundle even if there no …
Browse files Browse the repository at this point in the history
…i18n asset
  • Loading branch information
Egor Manzhula committed Sep 5, 2024
1 parent bf8c8ab commit 9db0dd4
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ilc/common/SdkOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class SdkOptions {
}

toJSON() {
if (!this.#i18n) {
return undefined;
}

return {
const json = {
i18n: this.#i18n,
cssBundle: this.#cssBundle,
};

const allValuesUndefined = Object.values(json).every((value) => value === undefined);

return allValuesUndefined ? undefined : json;
}
}

Expand Down
72 changes: 72 additions & 0 deletions ilc/common/SdkOptions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const { expect } = require('chai');
const { SdkOptions } = require('./SdkOptions');

describe('SdkOptions Class', () => {
it('should return i18n and cssBundle when both are provided', () => {
const params = {
i18n: { manifestPath: '/path/to/manifest' },
cssBundle: '/path/to/cssBundle',
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.deep.equal({
i18n: params.i18n,
cssBundle: params.cssBundle,
});
});

it('should return only i18n when cssBundle is not provided', () => {
const params = {
i18n: { manifestPath: '/path/to/manifest' },
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.deep.equal({
i18n: params.i18n,
cssBundle: undefined,
});
});

it('should return only cssBundle when i18n is not provided', () => {
const params = {
cssBundle: '/path/to/cssBundle',
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.deep.equal({
i18n: undefined,
cssBundle: params.cssBundle,
});
});

it('should return undefined when no params are provided', () => {
const sdkOptions = new SdkOptions();

const result = sdkOptions.toJSON();
expect(result).to.be.undefined;
});

it('should return undefined when i18n does not have manifestPath and cssBundle is not provided', () => {
const params = {
i18n: {},
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.be.undefined;
});

it('should return undefined when both i18n and cssBundle are undefined', () => {
const params = {
i18n: undefined,
cssBundle: undefined,
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.be.undefined;
});
});

0 comments on commit 9db0dd4

Please sign in to comment.