-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from Relewise/feat/popularity-multiplier-selector
Feat: support popularity multiplier selectors
- Loading branch information
Showing
5 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/client/src/builders/recommendation/products/popularityMultiplierBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { DataKeyPopularityMultiplierSelector, PopularityMultiplierSelector } from '../../../models/data-contracts'; | ||
|
||
export class PopularityMultiplierBuilder { | ||
private popularityMultiplierSelector: PopularityMultiplierSelector | null = null; | ||
|
||
public setDataKeyPopularityMultiplierSelector(selector: { key?: string | null }): this { | ||
const dataKeyPopularityMultiplierSelector: DataKeyPopularityMultiplierSelector = { | ||
$type: 'Relewise.Client.Requests.PopularityMultiplierSelectors.DataKeyPopularityMultiplierSelector, Relewise.Client', | ||
...selector, | ||
} | ||
|
||
this.popularityMultiplierSelector = dataKeyPopularityMultiplierSelector; | ||
return this; | ||
} | ||
|
||
build(): PopularityMultiplierSelector | null { | ||
return this.popularityMultiplierSelector; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/client/tests/unit-tests/builders/recommendation/popularProductsBuilder.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { UserFactory } from '../../../../src/factory'; | ||
import { test, expect } from '@jest/globals' | ||
import { PopularProductsRequest } from '../../../../src/models/data-contracts'; | ||
import { PopularProductsBuilder } from '../../../../src'; | ||
|
||
function baseBuilder() { | ||
return new PopularProductsBuilder({ | ||
language: 'da-DK', | ||
currency: 'DKK', | ||
displayedAtLocation: 'unit test', | ||
user: UserFactory.anonymous(), | ||
}); | ||
}; | ||
|
||
test('setPopularityMultiplier', () => { | ||
const key: string = 'data-key'; | ||
|
||
const subject: PopularProductsRequest = baseBuilder() | ||
.setPopularityMultiplier(pm => pm.setDataKeyPopularityMultiplierSelector({ key: key })) | ||
.build(); | ||
|
||
expect(subject.popularityMultiplier?.key).toBe(key); | ||
}); |