kontent-ai / delivery-sdk-js

Kontent Delivery SDK for Javascript
https://kontent.ai
MIT License
50 stars 34 forks source link

Default Language parameter is not overwritten when a language Parameter is applied at the query level #369

Closed Nickm615 closed 1 year ago

Nickm615 commented 1 year ago

Brief bug description

The defaultLanguage parameter applied in the client should be overwritten when another language parameter is applied to an individual query, instead they are both applied

Repro steps

Instantiate a delivery client in a local JS environment Add defaultLanguage: 'yourLanguageCodename' to the client Create a query with languageParameter of another language applied Send request and check URL value of the response object to see that both language parameters have been added.

My example:

const deliveryClient = new DeliveryClient({
    environmentId: 'a7ce696f-1479-0096-8d1d-f7a02aefa1d5',
    defaultLanguage: 'default'
})

const response = await(deliveryClient.items().languageParameter('es_ES').toAllPromise())

console.log(response.data.responses)

Expected behavior

The Language Parameter on the query level should overwrite the default language, and the URL should only contain the single language parameter

Test environment

Node.js v 18.16.0

Additional context

I believe the issue is stemming from this: https://github.com/kontent-ai/delivery-sdk-js/blob/master/lib/query/common/base-query.class.ts#L119-L128C6

image

Specifically line 122, the .find() predicate will never return true, since the result of this.getParameters() isn't exactly equal to 'language'

Nickm615 commented 1 year ago

@Enngage Could you assign this issue to me?

Enngage commented 1 year ago

@Nickm615 you got it and nice catch!

Enngage commented 1 year ago

Merged to main.