Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: linting issue of Set consent Language without fetch request #453

Merged
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
9 changes: 8 additions & 1 deletion modules/core/src/GVL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class GVL extends Cloneable<GVL> implements VendorList {
* [[VendorList]] object or a version number represented as a string or
* number to download. If nothing is passed the latest version of the GVL
* will be loaded
* @param options - it is an optional object where the default language can be set
* @param {GvlCreationOptions} [options] - it is an optional object where the default language can be set
*/
public constructor(versionOrVendorList?: VersionOrVendorList, options?: GvlCreationOptions) {

Expand All @@ -251,12 +251,19 @@ export class GVL extends Cloneable<GVL> implements VendorList {
let url = GVL.baseUrl;

let parsedLanguage: string = options?.language;

if (parsedLanguage) {

try {

parsedLanguage = GVL.consentLanguages.parseLanguage(parsedLanguage);

} catch (e) {

throw new GVLError('Error during parsing the language: ' + e.message);

}

}

this.lang_ = parsedLanguage || GVL.DEFAULT_LANGUAGE;
Expand Down
18 changes: 15 additions & 3 deletions modules/core/test/GVL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,34 @@ describe('GVL', (): void => {
});

it('should create a new GVL with a valid language', (): void => {
const gvl: GVL = new GVL(vendorlistJson22, { language: 'ES' });

const gvl: GVL = new GVL(vendorlistJson22, {language: 'ES'});

assertPopulated(gvl, vendorlistJson22);
expect(gvl.language).to.equal('ES');

});

it('should not create GVL object because with a invalid language', (): void => {

let gvl;

try {
gvl = new GVL(vendorlistJson22, { language: 'EQ' });

gvl = new GVL(vendorlistJson22, {language: 'EQ'});

} catch (error) {

expect(error instanceof GVLError).to.equal(true);

} finally {

expect(gvl).to.equal(undefined);

}
assert.throws(() => new GVL(vendorlistJson22, { language: 'EQ' }), GVLError);

assert.throws(() => new GVL(vendorlistJson22, {language: 'EQ'}), GVLError);

});

it('should clone all values', (): void => {
Expand Down
Loading