diff --git a/ilc/common/SdkOptions.js b/ilc/common/SdkOptions.js index a6a06590..2b864d90 100644 --- a/ilc/common/SdkOptions.js +++ b/ilc/common/SdkOptions.js @@ -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; } } diff --git a/ilc/common/SdkOptions.spec.js b/ilc/common/SdkOptions.spec.js new file mode 100644 index 00000000..dd83da1a --- /dev/null +++ b/ilc/common/SdkOptions.spec.js @@ -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; + }); +});