Files
medusa-store/packages/utils/src/common/__tests__/pick-value-from-object.spec.ts
Riqwan Thamir b782d3bcb7 feat(utils,types): added item/shipping adjustments for order/items/shipping_methods (#6050)
what:

- adds compute actions for the following cases:
  - items => each & across
  - shipping_method => each & across
  - order
- adds a remove compute actions when code is no longer present in adjustments array

RESOLVES CORE-1625
RESOLVES CORE-1626
RESOLVES CORE-1627
RESOLVES CORE-1628
RESOLVES CORE-1585
2024-01-12 13:00:06 +00:00

112 lines
2.6 KiB
TypeScript

import { pickValueFromObject } from "../pick-value-from-object"
describe("pickValueFromObject", function () {
it("should return true or false for different types of data", function () {
const expectations = [
{
input: {
1: "attribute.another_attribute",
2: {
attribute: {
another_attribute: "test",
},
},
},
output: "test",
},
{
input: {
1: "attribute.another_attribute.array_attribute",
2: {
attribute: {
another_attribute: [
{
array_attribute: "test 1",
},
{
array_attribute: "test 2",
},
],
},
},
},
output: ["test 1", "test 2"],
},
{
input: {
1: "attribute.another_attribute.array_attribute.deep_array_attribute",
2: {
attribute: {
another_attribute: [
{
array_attribute: [
{
deep_array_attribute: "test 1",
},
{
deep_array_attribute: "test 2",
},
],
},
{
array_attribute: [],
},
],
},
},
},
output: ["test 1", "test 2"],
},
{
input: {
1: "attribute.another_attribute.array_attribute",
2: {
attribute: {
another_attribute: [
{
array_attribute: [
{
deep_array_attribute: "test 1",
},
{
deep_array_attribute: "test 2",
},
],
},
{
array_attribute: [],
},
],
},
},
},
output: [
{
deep_array_attribute: "test 1",
},
{
deep_array_attribute: "test 2",
},
],
},
{
input: {
1: "attribute.missing_attribute",
2: {
attribute: {
another_attribute: "test",
},
},
},
output: undefined,
},
]
expectations.forEach((expectation) => {
expect(
pickValueFromObject(expectation.input["1"], expectation.input["2"])
).toEqual(expectation.output)
})
})
})