@reactionary/provider-medusa 0.1.13 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/client.js +2 -23
- package/core/initialize.js +4 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/providers/cart.provider.js +68 -58
- package/providers/category.provider.js +19 -53
- package/providers/checkout.provider.js +18 -40
- package/providers/identity.provider.js +9 -25
- package/providers/inventory.provider.js +7 -22
- package/providers/price.provider.js +8 -13
- package/providers/product-search.provider.js +31 -35
- package/providers/product.provider.js +13 -13
- package/providers/profile.provider.js +323 -0
- package/schema/capabilities.schema.js +2 -1
- package/src/core/client.d.ts +0 -35
- package/src/index.d.ts +1 -0
- package/src/providers/cart.provider.d.ts +10 -10
- package/src/providers/category.provider.d.ts +8 -50
- package/src/providers/checkout.provider.d.ts +10 -10
- package/src/providers/identity.provider.d.ts +5 -5
- package/src/providers/inventory.provider.d.ts +2 -2
- package/src/providers/price.provider.d.ts +3 -3
- package/src/providers/product-search.provider.d.ts +3 -17
- package/src/providers/product.provider.d.ts +4 -4
- package/src/providers/profile.provider.d.ts +30 -0
- package/src/schema/capabilities.schema.d.ts +3 -2
- package/test/cart.provider.spec.js +69 -49
- package/test/category.provider.spec.js +125 -63
- package/test/checkout.spec.js +80 -49
- package/test/identity.provider.spec.js +22 -7
- package/test/inventory.provider.spec.js +35 -24
- package/test/large-cart.provider.spec.js +57 -31
- package/test/price.provider.spec.js +57 -36
- package/test/product.provider.spec.js +78 -49
- package/test/search.provider.spec.js +47 -20
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Cache, Product, ProductAttribute, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, RequestContext } from '@reactionary/core';
|
|
1
|
+
import type { Cache, NotFoundError, Product, ProductAttribute, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, RequestContext, Result } from '@reactionary/core';
|
|
2
2
|
import { ProductProvider } from '@reactionary/core';
|
|
3
3
|
import type { MedusaClient } from '../core/client.js';
|
|
4
4
|
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
@@ -7,9 +7,9 @@ export declare class MedusaProductProvider extends ProductProvider {
|
|
|
7
7
|
client: MedusaClient;
|
|
8
8
|
protected config: MedusaConfiguration;
|
|
9
9
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
10
|
-
getById(payload: ProductQueryById): Promise<Product
|
|
11
|
-
getBySlug(payload: ProductQueryBySlug): Promise<Product
|
|
12
|
-
getBySKU(payload: ProductQueryBySKU): Promise<Product
|
|
10
|
+
getById(payload: ProductQueryById): Promise<Result<Product>>;
|
|
11
|
+
getBySlug(payload: ProductQueryBySlug): Promise<Result<Product, NotFoundError>>;
|
|
12
|
+
getBySKU(payload: ProductQueryBySKU): Promise<Result<Product>>;
|
|
13
13
|
protected parseSingle(_body: StoreProduct): Product;
|
|
14
14
|
protected parseVariant(variant: StoreProductVariant, product: StoreProduct): {
|
|
15
15
|
identifier: {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Profile, type ProfileMutationAddShippingAddress, type ProfileMutationMakeShippingAddressDefault, type ProfileMutationRemoveShippingAddress, type ProfileMutationSetBillingAddress, type ProfileMutationUpdate, type ProfileMutationUpdateShippingAddress, type ProfileQuerySelf as ProfileQueryById, type RequestContext, type Cache, type Result, type NotFoundError, ProfileProvider, type Address } from '@reactionary/core';
|
|
2
|
+
import type { MedusaConfiguration } from '../schema/configuration.schema.js';
|
|
3
|
+
import type { MedusaClient } from '../core/client.js';
|
|
4
|
+
import type { StoreCreateCustomerAddress, StoreCustomer, StoreCustomerAddress } from '@medusajs/types';
|
|
5
|
+
/**
|
|
6
|
+
* Medusa Profile Provider
|
|
7
|
+
*
|
|
8
|
+
* Implements profile management using Medusa's customer APIs.
|
|
9
|
+
*
|
|
10
|
+
* TODO:
|
|
11
|
+
* - handle email and phone verification status properly using metadata or other means.
|
|
12
|
+
* - handle guest user scenarios (if applicable).
|
|
13
|
+
* - improve error handling and edge cases.
|
|
14
|
+
*/
|
|
15
|
+
export declare class MedusaProfileProvider extends ProfileProvider {
|
|
16
|
+
protected config: MedusaConfiguration;
|
|
17
|
+
protected client: MedusaClient;
|
|
18
|
+
protected includedFields: string[];
|
|
19
|
+
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, client: MedusaClient);
|
|
20
|
+
getById(payload: ProfileQueryById): Promise<Result<Profile, NotFoundError>>;
|
|
21
|
+
update(payload: ProfileMutationUpdate): Promise<Result<Profile, NotFoundError>>;
|
|
22
|
+
addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
23
|
+
updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
24
|
+
removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
25
|
+
makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<Profile, NotFoundError>>;
|
|
26
|
+
setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<Profile, NotFoundError>>;
|
|
27
|
+
protected createMedusaAddress(address: Address): StoreCreateCustomerAddress;
|
|
28
|
+
protected parseAddress(address: StoreCustomerAddress): Address;
|
|
29
|
+
protected parseSingle(customer: StoreCustomer): Profile;
|
|
30
|
+
}
|
|
@@ -2,11 +2,12 @@ import type { z } from 'zod';
|
|
|
2
2
|
export declare const MedusaCapabilitiesSchema: z.ZodObject<{
|
|
3
3
|
price: z.ZodOptional<z.ZodBoolean>;
|
|
4
4
|
product: z.ZodOptional<z.ZodBoolean>;
|
|
5
|
-
identity: z.ZodOptional<z.ZodBoolean>;
|
|
6
5
|
cart: z.ZodOptional<z.ZodBoolean>;
|
|
7
6
|
checkout: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
-
|
|
7
|
+
identity: z.ZodOptional<z.ZodBoolean>;
|
|
9
8
|
inventory: z.ZodOptional<z.ZodBoolean>;
|
|
10
9
|
category: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
profile: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
productSearch: z.ZodOptional<z.ZodBoolean>;
|
|
11
12
|
}, z.core.$loose>;
|
|
12
13
|
export type MedusaCapabilities = z.infer<typeof MedusaCapabilitiesSchema>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NoOpCache, createInitialRequestContext } from "@reactionary/core";
|
|
2
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
1
|
+
import { NoOpCache, createInitialRequestContext, unwrapValue } from "@reactionary/core";
|
|
2
|
+
import { assert, beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
import { MedusaClient } from "../core/client.js";
|
|
4
4
|
import { MedusaCartProvider } from "../providers/cart.provider.js";
|
|
5
5
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
@@ -16,88 +16,99 @@ describe("Medusa Cart Provider", () => {
|
|
|
16
16
|
provider = new MedusaCartProvider(getMedusaTestConfiguration(), new NoOpCache(), reqCtx, client);
|
|
17
17
|
});
|
|
18
18
|
describe("anonymous sessions", () => {
|
|
19
|
-
it("should
|
|
19
|
+
it("should get a NotFound for an unknown identifier", async () => {
|
|
20
20
|
const cart = await provider.getById({
|
|
21
21
|
cart: { key: "" }
|
|
22
22
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (cart.success) {
|
|
24
|
+
assert.fail();
|
|
25
|
+
}
|
|
26
|
+
expect(cart.error.type).toBe("NotFound");
|
|
26
27
|
});
|
|
27
28
|
it("should be able to add an item to a cart", async () => {
|
|
28
29
|
const cart = await provider.add({
|
|
29
|
-
cart: { key: "" },
|
|
30
30
|
variant: {
|
|
31
31
|
sku: testData.skuWithoutTiers
|
|
32
32
|
},
|
|
33
33
|
quantity: 1
|
|
34
34
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(cart.
|
|
39
|
-
expect(cart.items
|
|
40
|
-
expect(cart.items[0].
|
|
41
|
-
expect(cart.
|
|
42
|
-
expect(cart.price.
|
|
43
|
-
expect(cart.
|
|
44
|
-
expect(cart.
|
|
35
|
+
if (!cart.success) {
|
|
36
|
+
assert.fail();
|
|
37
|
+
}
|
|
38
|
+
expect(cart.value.identifier.key).toBeDefined();
|
|
39
|
+
expect(cart.value.items.length).toBe(1);
|
|
40
|
+
expect(cart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
|
|
41
|
+
expect(cart.value.items[0].quantity).toBe(1);
|
|
42
|
+
expect(cart.value.items[0].price.totalPrice.value).toBeGreaterThan(0);
|
|
43
|
+
expect(cart.value.items[0].price.totalPrice.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
44
|
+
expect(cart.value.price.grandTotal.value).toBeGreaterThan(0);
|
|
45
|
+
expect(cart.value.price.grandTotal.currency).toBe(reqCtx.languageContext.currencyCode);
|
|
46
|
+
expect(cart.value.price.grandTotal.value).toBe(cart.value.items[0].price.totalPrice.value);
|
|
45
47
|
});
|
|
46
48
|
it("can add multiple different items to a cart", async () => {
|
|
47
49
|
const cart = await provider.add({
|
|
48
|
-
cart: { key: "" },
|
|
49
50
|
variant: {
|
|
50
51
|
sku: testData.skuWithoutTiers
|
|
51
52
|
},
|
|
52
53
|
quantity: 1
|
|
53
54
|
});
|
|
55
|
+
if (!cart.success) {
|
|
56
|
+
assert.fail();
|
|
57
|
+
}
|
|
54
58
|
const updatedCart = await provider.add({
|
|
55
|
-
cart: cart.identifier,
|
|
59
|
+
cart: cart.value.identifier,
|
|
56
60
|
variant: {
|
|
57
61
|
sku: testData.skuWithTiers
|
|
58
62
|
},
|
|
59
63
|
quantity: 2
|
|
60
64
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
expect(updatedCart.items
|
|
65
|
-
expect(updatedCart.items[
|
|
65
|
+
if (!updatedCart.success) {
|
|
66
|
+
assert.fail();
|
|
67
|
+
}
|
|
68
|
+
expect(updatedCart.value.items.length).toBe(2);
|
|
69
|
+
expect(updatedCart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
|
|
70
|
+
expect(updatedCart.value.items[0].quantity).toBe(1);
|
|
71
|
+
expect(updatedCart.value.items[1].variant.sku).toBe(testData.skuWithTiers);
|
|
72
|
+
expect(updatedCart.value.items[1].quantity).toBe(2);
|
|
66
73
|
});
|
|
67
74
|
it("should be able to change quantity of an item in a cart", async () => {
|
|
68
75
|
const cart = await provider.add({
|
|
69
|
-
cart: { key: "" },
|
|
70
76
|
variant: {
|
|
71
77
|
sku: testData.skuWithoutTiers
|
|
72
78
|
},
|
|
73
79
|
quantity: 1
|
|
74
80
|
});
|
|
81
|
+
if (!cart.success) {
|
|
82
|
+
assert.fail();
|
|
83
|
+
}
|
|
75
84
|
const updatedCart = await provider.changeQuantity({
|
|
76
|
-
cart: cart.identifier,
|
|
77
|
-
item: cart.items[0].identifier,
|
|
85
|
+
cart: cart.value.identifier,
|
|
86
|
+
item: cart.value.items[0].identifier,
|
|
78
87
|
quantity: 3
|
|
79
88
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
expect(updatedCart.items
|
|
84
|
-
expect(updatedCart.items[0].
|
|
89
|
+
if (!updatedCart.success) {
|
|
90
|
+
assert.fail();
|
|
91
|
+
}
|
|
92
|
+
expect(updatedCart.value.items.length).toBe(1);
|
|
93
|
+
expect(updatedCart.value.items[0].variant.sku).toBe(testData.skuWithoutTiers);
|
|
94
|
+
expect(updatedCart.value.items[0].quantity).toBe(3);
|
|
95
|
+
expect(updatedCart.value.items[0].price.totalPrice.value).toBe(cart.value.items[0].price.totalPrice.value * 3);
|
|
96
|
+
expect(updatedCart.value.items[0].price.unitPrice.value).toBe(cart.value.items[0].price.unitPrice.value);
|
|
85
97
|
});
|
|
86
98
|
it("cannot set quantity below 1", async () => {
|
|
87
|
-
const cart = await provider.add({
|
|
88
|
-
cart: { key: "" },
|
|
99
|
+
const cart = unwrapValue(await provider.add({
|
|
89
100
|
variant: {
|
|
90
101
|
sku: testData.skuWithoutTiers
|
|
91
102
|
},
|
|
92
103
|
quantity: 1
|
|
93
|
-
});
|
|
104
|
+
}));
|
|
94
105
|
let updatedCart;
|
|
95
106
|
try {
|
|
96
|
-
updatedCart = await provider.changeQuantity({
|
|
107
|
+
updatedCart = unwrapValue(await provider.changeQuantity({
|
|
97
108
|
cart: cart.identifier,
|
|
98
109
|
item: cart.items[0].identifier,
|
|
99
110
|
quantity: 0
|
|
100
|
-
});
|
|
111
|
+
}));
|
|
101
112
|
expect(updatedCart).toBeDefined();
|
|
102
113
|
} catch (error) {
|
|
103
114
|
expect(error).toBeDefined();
|
|
@@ -107,37 +118,46 @@ describe("Medusa Cart Provider", () => {
|
|
|
107
118
|
});
|
|
108
119
|
it("should be able to remove an item from a cart", async () => {
|
|
109
120
|
const cart = await provider.add({
|
|
110
|
-
cart: { key: "" },
|
|
111
121
|
variant: {
|
|
112
122
|
sku: testData.skuWithoutTiers
|
|
113
123
|
},
|
|
114
124
|
quantity: 1
|
|
115
125
|
});
|
|
126
|
+
if (!cart.success) {
|
|
127
|
+
assert.fail();
|
|
128
|
+
}
|
|
116
129
|
const updatedCart = await provider.remove({
|
|
117
|
-
cart: cart.identifier,
|
|
118
|
-
item: cart.items[0].identifier
|
|
130
|
+
cart: cart.value.identifier,
|
|
131
|
+
item: cart.value.items[0].identifier
|
|
119
132
|
});
|
|
120
|
-
|
|
133
|
+
if (!updatedCart.success) {
|
|
134
|
+
assert.fail();
|
|
135
|
+
}
|
|
136
|
+
expect(updatedCart.value.items.length).toBe(0);
|
|
121
137
|
});
|
|
122
138
|
it("should be able to delete a cart", async () => {
|
|
123
139
|
const cart = await provider.add({
|
|
124
|
-
cart: { key: "" },
|
|
125
140
|
variant: {
|
|
126
141
|
sku: testData.skuWithoutTiers
|
|
127
142
|
},
|
|
128
143
|
quantity: 1
|
|
129
144
|
});
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
if (!cart.success) {
|
|
146
|
+
assert.fail();
|
|
147
|
+
}
|
|
148
|
+
expect(cart.value.items.length).toBe(1);
|
|
149
|
+
expect(cart.value.identifier.key).toBeTruthy();
|
|
132
150
|
const deletedCart = await provider.deleteCart({
|
|
133
|
-
cart: cart.identifier
|
|
151
|
+
cart: cart.value.identifier
|
|
134
152
|
});
|
|
135
|
-
expect(deletedCart.
|
|
136
|
-
expect(deletedCart.identifier.key).toBe("");
|
|
153
|
+
expect(deletedCart.success).toBe(true);
|
|
137
154
|
const originalCart = await provider.getById({
|
|
138
|
-
cart: cart.identifier
|
|
155
|
+
cart: cart.value.identifier
|
|
139
156
|
});
|
|
140
|
-
|
|
157
|
+
if (originalCart.success) {
|
|
158
|
+
assert.fail();
|
|
159
|
+
}
|
|
160
|
+
expect(originalCart.error.type).toBe("NotFound");
|
|
141
161
|
});
|
|
142
162
|
});
|
|
143
163
|
});
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CategorySchema,
|
|
4
|
+
NoOpCache,
|
|
5
|
+
createInitialRequestContext
|
|
6
|
+
} from "@reactionary/core";
|
|
3
7
|
import { MedusaCategoryProvider } from "../providers/category.provider.js";
|
|
4
8
|
import { getMedusaTestConfiguration } from "./test-utils.js";
|
|
5
|
-
import { describe, expect, it, beforeEach } from "vitest";
|
|
9
|
+
import { describe, expect, it, beforeEach, assert } from "vitest";
|
|
6
10
|
import { MedusaClient } from "../core/client.js";
|
|
7
11
|
const testData = {
|
|
8
12
|
topCategories: [
|
|
@@ -31,95 +35,153 @@ describe("Medusa Category Provider", () => {
|
|
|
31
35
|
reqCtx = createInitialRequestContext();
|
|
32
36
|
const config = getMedusaTestConfiguration();
|
|
33
37
|
const client = new MedusaClient(config, reqCtx);
|
|
34
|
-
provider = new MedusaCategoryProvider(
|
|
38
|
+
provider = new MedusaCategoryProvider(
|
|
39
|
+
config,
|
|
40
|
+
new NoOpCache(),
|
|
41
|
+
reqCtx,
|
|
42
|
+
client
|
|
43
|
+
);
|
|
35
44
|
});
|
|
36
45
|
it("should be able to get top-categories", async () => {
|
|
37
|
-
const result = await provider.findTopCategories({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
const result = await provider.findTopCategories({
|
|
47
|
+
paginationOptions: { pageSize: 10, pageNumber: 1 }
|
|
48
|
+
});
|
|
49
|
+
if (!result.success) {
|
|
50
|
+
assert.fail();
|
|
51
|
+
}
|
|
52
|
+
expect(result.value.items.length).toBeGreaterThan(0);
|
|
53
|
+
expect(result.value.items[0].identifier.key).toBe(
|
|
54
|
+
testData.topCategories[0].key
|
|
55
|
+
);
|
|
56
|
+
expect(result.value.items[0].name).toBe(testData.topCategories[0].name);
|
|
57
|
+
expect(result.value.items[1].identifier.key).toBe(
|
|
58
|
+
testData.topCategories[1].key
|
|
59
|
+
);
|
|
60
|
+
expect(result.value.items[1].name).toBe(testData.topCategories[1].name);
|
|
43
61
|
});
|
|
44
62
|
it("should be able to get child categories for a category", async () => {
|
|
45
|
-
const result = await provider.findChildCategories({
|
|
63
|
+
const result = await provider.findChildCategories({
|
|
64
|
+
parentId: { key: testData.topCategories[0].key },
|
|
65
|
+
paginationOptions: { pageSize: 10, pageNumber: 1 }
|
|
66
|
+
});
|
|
67
|
+
if (!result.success) {
|
|
68
|
+
assert.fail();
|
|
69
|
+
}
|
|
46
70
|
for (const verificationData of testData.childCategoriesOfFirstTopcategory) {
|
|
47
|
-
const found = result.items.find(
|
|
71
|
+
const found = result.value.items.find(
|
|
72
|
+
(item) => item.identifier.key === verificationData.key
|
|
73
|
+
);
|
|
48
74
|
expect(found).toBeDefined();
|
|
49
75
|
expect(found?.name).toBe(verificationData.name);
|
|
50
76
|
}
|
|
51
77
|
});
|
|
52
78
|
it("should be able to get child categories for a category, paged", async () => {
|
|
53
|
-
const result = await provider.findChildCategories({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
expect(
|
|
61
|
-
expect(
|
|
62
|
-
expect(
|
|
63
|
-
expect(
|
|
64
|
-
expect(
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
const result = await provider.findChildCategories({
|
|
80
|
+
parentId: { key: testData.topCategories[0].key },
|
|
81
|
+
paginationOptions: { pageSize: 1, pageNumber: 1 }
|
|
82
|
+
});
|
|
83
|
+
if (!result.success) {
|
|
84
|
+
assert.fail();
|
|
85
|
+
}
|
|
86
|
+
expect(result.value.items.length).toBeGreaterThan(0);
|
|
87
|
+
expect(result.value.totalCount).toBeGreaterThan(1);
|
|
88
|
+
expect(result.value.totalPages).toBeGreaterThan(1);
|
|
89
|
+
expect(result.value.pageSize).toBe(1);
|
|
90
|
+
expect(result.value.pageNumber).toBe(1);
|
|
91
|
+
const result2 = await provider.findChildCategories({
|
|
92
|
+
parentId: { key: testData.topCategories[0].key },
|
|
93
|
+
paginationOptions: { pageSize: 1, pageNumber: 2 }
|
|
94
|
+
});
|
|
95
|
+
if (!result2.success) {
|
|
96
|
+
assert.fail();
|
|
97
|
+
}
|
|
98
|
+
expect(result2.value.items.length).toBeGreaterThan(0);
|
|
99
|
+
expect(result2.value.totalCount).toBeGreaterThan(1);
|
|
100
|
+
expect(result2.value.totalPages).toBeGreaterThan(1);
|
|
101
|
+
expect(result2.value.pageSize).toBe(1);
|
|
102
|
+
expect(result2.value.pageNumber).toBe(2);
|
|
103
|
+
for (const item of result2.value.items) {
|
|
104
|
+
expect(
|
|
105
|
+
result.value.items.find((i) => i.identifier.key === item.identifier.key)
|
|
106
|
+
).toBeUndefined();
|
|
67
107
|
}
|
|
68
108
|
});
|
|
69
109
|
it("can load all breadcrumbs for a category", async () => {
|
|
70
110
|
const leaf = testData.breadCrumb[testData.breadCrumb.length - 1];
|
|
71
|
-
const result = await provider.getBreadcrumbPathToCategory({
|
|
72
|
-
|
|
111
|
+
const result = await provider.getBreadcrumbPathToCategory({
|
|
112
|
+
id: { key: leaf }
|
|
113
|
+
});
|
|
114
|
+
if (!result.success) {
|
|
115
|
+
assert.fail();
|
|
116
|
+
}
|
|
117
|
+
expect(result.value.length).toBe(testData.breadCrumb.length);
|
|
73
118
|
for (let i = 0; i < testData.breadCrumb.length; i++) {
|
|
74
|
-
expect(result[i].identifier.key).toBe(testData.breadCrumb[i]);
|
|
119
|
+
expect(result.value[i].identifier.key).toBe(testData.breadCrumb[i]);
|
|
75
120
|
}
|
|
76
121
|
});
|
|
77
122
|
it("should be able to get a category by slug", async () => {
|
|
78
|
-
const result = await provider.getBySlug({
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
expect(result.parentCategory).toBeUndefined();
|
|
84
|
-
expect(result.text).not.toBe("");
|
|
85
|
-
expect(result.meta.placeholder).toBe(false);
|
|
123
|
+
const result = await provider.getBySlug({
|
|
124
|
+
slug: testData.topCategories[0].slug
|
|
125
|
+
});
|
|
126
|
+
if (!result.success) {
|
|
127
|
+
assert.fail();
|
|
86
128
|
}
|
|
129
|
+
expect(result.value.name).toBe(testData.topCategories[0].name);
|
|
130
|
+
expect(result.value.slug).toBe(testData.topCategories[0].slug);
|
|
131
|
+
expect(result.value.parentCategory).toBeUndefined();
|
|
132
|
+
expect(result.value.text).not.toBe("");
|
|
87
133
|
});
|
|
88
|
-
it("returns
|
|
134
|
+
it("returns NotFound if looking for slug that does not exist", async () => {
|
|
89
135
|
const result = await provider.getBySlug({ slug: "non-existent-slug" });
|
|
90
|
-
|
|
136
|
+
if (result.success) {
|
|
137
|
+
assert.fail();
|
|
138
|
+
}
|
|
139
|
+
expect(result.error.type).toBe("NotFound");
|
|
91
140
|
});
|
|
92
141
|
it("should be able to get a category by id", async () => {
|
|
93
|
-
const result = await provider.getById({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
expect(result.
|
|
142
|
+
const result = await provider.getById({
|
|
143
|
+
id: { key: testData.topCategories[0].key }
|
|
144
|
+
});
|
|
145
|
+
if (!result.success) {
|
|
146
|
+
assert.fail();
|
|
147
|
+
}
|
|
148
|
+
expect(result.value.identifier.key).toBe(testData.topCategories[0].key);
|
|
149
|
+
expect(result.value.name).toBe(testData.topCategories[0].name);
|
|
150
|
+
expect(result.value.slug).toBe(testData.topCategories[0].slug);
|
|
151
|
+
expect(result.value.parentCategory).toBeUndefined();
|
|
152
|
+
expect(result.value.text).toBe(testData.topCategories[0].text);
|
|
100
153
|
});
|
|
101
154
|
it.skip("should be able to get a category by id in alternate language", async () => {
|
|
102
155
|
reqCtx.languageContext.locale = "da";
|
|
103
|
-
const result = await provider.getById({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
expect(result.
|
|
156
|
+
const result = await provider.getById({
|
|
157
|
+
id: { key: testData.topCategories[0].key }
|
|
158
|
+
});
|
|
159
|
+
if (!result.success) {
|
|
160
|
+
assert.fail();
|
|
161
|
+
}
|
|
162
|
+
expect(result.value.identifier.key).toBe(testData.topCategories[0].key);
|
|
163
|
+
expect(result.value.name).toBe(testData.topCategories[0].name + " [da Version]");
|
|
164
|
+
expect(result.value.slug).toBe(testData.topCategories[0].slug + "_da");
|
|
165
|
+
expect(result.value.parentCategory).toBeUndefined();
|
|
166
|
+
expect(result.value.text).toBe(testData.topCategories[0].text + " [da Version]");
|
|
110
167
|
});
|
|
111
|
-
it.skip("returns
|
|
168
|
+
it.skip("returns NotFound if you choose a language that is not available", async () => {
|
|
112
169
|
reqCtx.languageContext.locale = "fr-FR";
|
|
113
|
-
const result = await provider.getById({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
170
|
+
const result = await provider.getById({
|
|
171
|
+
id: { key: testData.topCategories[0].key }
|
|
172
|
+
});
|
|
173
|
+
if (result.success) {
|
|
174
|
+
assert.fail();
|
|
175
|
+
}
|
|
176
|
+
expect(result.error.type).toBe("NotFound");
|
|
119
177
|
});
|
|
120
|
-
it("returns
|
|
121
|
-
const result = await provider.getById({
|
|
122
|
-
|
|
123
|
-
|
|
178
|
+
it("returns NotFound if you search for a category that does not exist", async () => {
|
|
179
|
+
const result = await provider.getById({
|
|
180
|
+
id: { key: "non-existent-category" }
|
|
181
|
+
});
|
|
182
|
+
if (result.success) {
|
|
183
|
+
assert.fail();
|
|
184
|
+
}
|
|
185
|
+
expect(result.error.type).toBe("NotFound");
|
|
124
186
|
});
|
|
125
187
|
});
|