-
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.
- Loading branch information
Showing
6 changed files
with
132 additions
and
25 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
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
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
85 changes: 85 additions & 0 deletions
85
packages/integrations/tests/integration-tests/products/updates.integration.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,85 @@ | ||
import { test, expect } from '@jest/globals'; | ||
import { Integrator, ProductAdministrativeActionBuilder, ProductUpdateBuilder } from '../../../src'; | ||
import { DataValueFactory } from '@relewise/client'; | ||
const { npm_config_API_KEY: API_KEY, npm_config_DATASET_ID: DATASET_ID, npm_config_SERVER_URL: SERVER_URL } = process.env; | ||
|
||
const integrator = new Integrator(DATASET_ID!, API_KEY!, { serverUrl: SERVER_URL }); | ||
|
||
const unixTimeStamp: number = Date.now(); | ||
|
||
test('Create Product', async() => { | ||
const product = new ProductUpdateBuilder({ | ||
id: '1234', | ||
productUpdateKind: 'ReplaceProvidedProperties', | ||
variantUpdateKind: 'ReplaceProvidedProperties', | ||
}) | ||
.displayName([ | ||
{ language: 'da', value: 'Toaster' }, | ||
]) | ||
.data({ | ||
'UnixTimestamp': DataValueFactory.number(unixTimeStamp), | ||
'Description': DataValueFactory.string('Really nice product'), | ||
'Tags': DataValueFactory.stringCollection(['fall collection', 'blue', 'good-deal']), | ||
'InStock': DataValueFactory.boolean(true), | ||
}) | ||
.assortments([1, 2, 3]) | ||
.brand({ id: '1', displayName: 'Relewise' }) | ||
.listPrice([{ amount: 100, currency: 'DKK' }]) | ||
.salesPrice([{ amount: 50, currency: 'DKK' }]); | ||
|
||
await integrator.updateProduct(product.build()); | ||
|
||
const enable = new ProductAdministrativeActionBuilder({ | ||
filters: (f) => f.addProductDataFilter('UnixTimeStamp', c => c.addEqualsCondition(DataValueFactory.number(unixTimeStamp))), | ||
productUpdateKind: 'Enable', | ||
}); | ||
integrator.productAdministrativeAction(enable.build()); | ||
|
||
const disable = new ProductAdministrativeActionBuilder({ | ||
filters: (f) => f.addProductDataFilter('UnixTimeStamp', c => c.addEqualsCondition(DataValueFactory.number(unixTimeStamp), /* negated: */ true)), | ||
productUpdateKind: 'Disable', | ||
}); | ||
integrator.productAdministrativeAction(disable.build()); | ||
}); | ||
|
||
test('Batch create products', async() => { | ||
const product = new ProductUpdateBuilder({ | ||
id: '1234', | ||
productUpdateKind: 'ReplaceProvidedProperties', | ||
variantUpdateKind: 'ReplaceProvidedProperties', | ||
}) | ||
.displayName([ | ||
{ language: 'da', value: 'Toaster' }, | ||
]) | ||
.data({ | ||
'UnixTimestamp': DataValueFactory.number(unixTimeStamp), | ||
'Description': DataValueFactory.string('Really nice product'), | ||
'Tags': DataValueFactory.stringCollection(['fall collection', 'blue', 'good-deal']), | ||
'InStock': DataValueFactory.boolean(true), | ||
}) | ||
.assortments([1, 2, 3]) | ||
.brand({ id: '1', displayName: 'Relewise' }) | ||
.listPrice([{ amount: 100, currency: 'DKK' }]) | ||
.salesPrice([{ amount: 50, currency: 'DKK' }]); | ||
|
||
const product2 = new ProductUpdateBuilder({ | ||
id: '4321', | ||
productUpdateKind: 'ReplaceProvidedProperties', | ||
variantUpdateKind: 'ReplaceProvidedProperties', | ||
}) | ||
.displayName([ | ||
{ language: 'da', value: 'Laptop' }, | ||
]) | ||
.data({ | ||
'UnixTimestamp': DataValueFactory.number(unixTimeStamp), | ||
'Description': DataValueFactory.string('Really nice product'), | ||
'Tags': DataValueFactory.stringCollection(['fall collection', 'blue', 'good-deal']), | ||
'InStock': DataValueFactory.boolean(true), | ||
}) | ||
.assortments([1, 2, 3]) | ||
.brand({ id: '1', displayName: 'Relewise' }) | ||
.listPrice([{ amount: 100, currency: 'DKK' }]) | ||
.salesPrice([{ amount: 50, currency: 'DKK' }]); | ||
|
||
await integrator.batch([product.build(), product2.build()]); | ||
}); |