Skip to content

Commit

Permalink
feat(business-unit): fixed issues with new sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
demeyerthom committed Aug 16, 2024
1 parent 97cce0e commit e50af4f
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/oauth/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe("OAuth2Server", () => {
addresses: [],
authenticationMode: "password",
isEmailVerified: true,
stores: [],
});

const response = await supertest(app)
Expand Down
12 changes: 8 additions & 4 deletions src/repositories/cart/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
type ProductPagedQueryResponse,
type ProductVariant,
} from "@commercetools/platform-sdk";
import { DirectDiscount } from "@commercetools/platform-sdk/dist/declarations/src/generated/models/cart";
import { v4 as uuidv4 } from "uuid";
import { CommercetoolsError } from "~src/exceptions";
import type { Writable } from "~src/types";
Expand Down Expand Up @@ -419,10 +420,13 @@ export class CartUpdateHandler
{ discounts }: CartSetDirectDiscountsAction,
) {
// Doesn't apply any discounts logic, just sets the directDiscounts field
resource.directDiscounts = discounts.map((discount) => ({
...discount,
id: uuidv4(),
}));
resource.directDiscounts = discounts.map(
(discount) =>
({
...discount,
id: uuidv4(),
}) as DirectDiscount,
);
}

setLineItemShippingDetails(
Expand Down
1 change: 1 addition & 0 deletions src/repositories/customer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class CustomerRepository extends AbstractResourceRepository<"customer"> {
context.projectKey,
this._storage,
),
stores: [],
};
return this.saveNew(context, resource);
}
Expand Down
3 changes: 1 addition & 2 deletions src/repositories/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
type StoreReference,
type StoreResourceIdentifier,
type Type,
type TypedMoney,
type _Money,
} from "@commercetools/platform-sdk";
import type { Request } from "express";
Expand Down Expand Up @@ -133,7 +132,7 @@ export const createCentPrecisionMoney = (value: _Money): CentPrecisionMoney => {
};
};

export const createTypedMoney = (value: _Money): TypedMoney => {
export const createTypedMoney = (value: _Money): CentPrecisionMoney => {
const result = createCentPrecisionMoney(value);
return result;
};
Expand Down
2 changes: 2 additions & 0 deletions src/repositories/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ProductTailoringRepository } from "~src/repositories/product-tailoring";
import { AbstractStorage } from "../storage";
import { AssociateRoleRepository } from "./associate-role";
import { AttributeGroupRepository } from "./attribute-group";
Expand Down Expand Up @@ -66,6 +67,7 @@ export const createRepositories = (storage: AbstractStorage) => ({
"product-discount": new ProductDiscountRepository(storage),
"product-projection": new ProductProjectionRepository(storage),
"product-selection": new ProductSelectionRepository(storage),
"product-tailoring": new ProductTailoringRepository(storage),
"project": new ProjectRepository(storage),
"review": new ReviewRepository(storage),
"quote": new QuoteRepository(storage),
Expand Down
34 changes: 34 additions & 0 deletions src/repositories/product-tailoring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type {
ProductTailoring,
ProductTailoringUpdateAction,
} from "@commercetools/platform-sdk";
import { AbstractStorage } from "~src/storage";
import {
AbstractResourceRepository,
AbstractUpdateHandler,
RepositoryContext,
UpdateHandlerInterface,
} from "./abstract";

export class ProductTailoringRepository extends AbstractResourceRepository<"product-tailoring"> {
constructor(storage: AbstractStorage) {
super("product-tailoring", storage);
this.actions = new ProductTailoringUpdateHandler(this._storage);
}

create(context: RepositoryContext, draft: any): ProductTailoring {
throw new Error("Create method for product-tailoring not implemented.");
}
}

class ProductTailoringUpdateHandler
extends AbstractUpdateHandler
implements
Partial<
UpdateHandlerInterface<ProductTailoring, ProductTailoringUpdateAction>
>
{
setSlug() {
throw new Error("SetSlug method for product-tailoring not implemented.");
}
}
11 changes: 10 additions & 1 deletion src/repositories/shipping-method/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type ShippingMethod,
type ShippingMethodAddShippingRateAction,
type ShippingMethodAddZoneAction,
type ShippingMethodChangeActiveAction,
type ShippingMethodChangeIsDefaultAction,
type ShippingMethodChangeNameAction,
type ShippingMethodRemoveZoneAction,
Expand All @@ -18,7 +19,7 @@ import {
type ZoneReference,
} from "@commercetools/platform-sdk";
import deepEqual from "deep-equal";
import type { Writable } from "../../types";
import type { Writable } from "~src/types";
import {
AbstractUpdateHandler,
RepositoryContext,
Expand Down Expand Up @@ -83,6 +84,14 @@ export class ShippingMethodUpdateHandler
});
}

changeActive(
_context: RepositoryContext,
resource: Writable<ShippingMethod>,
{ active }: ShippingMethodChangeActiveAction,
) {
resource.active = active;
}

changeIsDefault(
_context: RepositoryContext,
resource: Writable<ShippingMethod>,
Expand Down
1 change: 1 addition & 0 deletions src/repositories/shipping-method/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository<"shippi
const resource: ShippingMethod = {
...getBaseResourceProperties(),
...draft,
active: draft.active ?? true,
taxCategory: getReferenceFromResourceIdentifier(
draft.taxCategory,
context.projectKey,
Expand Down
2 changes: 2 additions & 0 deletions src/services/customer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe("Customer Update Actions", () => {
isEmailVerified: true,
authenticationMode: "Password", //default in Commercetools
version: 1,
stores: [],
};
ctMock.project("dummy").add("customer", customer);
});
Expand Down Expand Up @@ -467,6 +468,7 @@ describe("Customer Password Reset", () => {
isEmailVerified: true,
authenticationMode: "password",
custom: { type: { typeId: "type", id: "" }, fields: {} },
stores: [],
});
});

Expand Down
11 changes: 8 additions & 3 deletions src/services/my-customer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Customer,
CustomerChangePassword,
CustomerToken,
MyCustomerDraft,
Expand Down Expand Up @@ -73,6 +74,7 @@ describe("/me", () => {
isEmailVerified: true,
authenticationMode: "password",
custom: { type: { typeId: "type", id: "" }, fields: {} },
stores: [],
});
});

Expand Down Expand Up @@ -126,7 +128,7 @@ describe("/me", () => {
});

test("Change my password", async () => {
const customer = {
const customer: Customer = {
...getBaseResourceProperties(),
id: "customer-uuid",
email: "[email protected]",
Expand All @@ -135,6 +137,7 @@ describe("/me", () => {
isEmailVerified: true,
authenticationMode: "Password", //default in Commercetools
version: 1,
stores: [],
};
ctMock.project("dummy").add("customer", customer);

Expand Down Expand Up @@ -176,7 +179,7 @@ describe("/me", () => {
});

test("reset password flow", async () => {
const customer = {
const customer: Customer = {
...getBaseResourceProperties(),
id: "customer-uuid",
email: "[email protected]",
Expand All @@ -185,6 +188,7 @@ describe("/me", () => {
isEmailVerified: true,
authenticationMode: "Password", //default in Commercetools
version: 1,
stores: [],
};
ctMock.project("dummy").add("customer", customer);

Expand Down Expand Up @@ -225,7 +229,7 @@ describe("/me", () => {
});

test("verify email flow", async () => {
const customer = {
const customer: Customer = {
...getBaseResourceProperties(),
id: "customer-uuid",
email: "[email protected]",
Expand All @@ -234,6 +238,7 @@ describe("/me", () => {
isEmailVerified: false,
authenticationMode: "Password", //default in Commercetools
version: 1,
stores: [],
};
ctMock.project("dummy").add("customer", customer);

Expand Down
2 changes: 2 additions & 0 deletions src/storage/in-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
type Product,
type ProductDiscount,
type ProductProjection,
type ProductTailoring,
type ProductType,
type Project,
type Quote,
Expand Down Expand Up @@ -189,6 +190,7 @@ export class InMemoryStorage extends AbstractStorage {
"product-selection": new Map<string, any>(),
"product-type": new Map<string, ProductType>(),
"product-projection": new Map<string, ProductProjection>(),
"product-tailoring": new Map<string, ProductTailoring>(),
"review": new Map<string, any>(),
"shipping-method": new Map<string, ShippingMethod>(),
"staged-quote": new Map<string, StagedQuote>(),
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type ResourceMap = {
"product-price": ctp.StandalonePrice;
"product-projection": ctp.ProductProjection;
"product-selection": ctp.ProductSelection;
"product-tailoring": ctp.ProductTailoring;
"product-type": ctp.ProductType;
"product": ctp.Product;
"quote-request": ctp.QuoteRequest;
Expand Down Expand Up @@ -85,6 +86,7 @@ export type PagedQueryResponseMap = {
"product-price": ctp.StandalonePricePagedQueryResponse;
"product-projection": ctp.ProductProjectionPagedQueryResponse;
"product-selection": ctp.ProductSelectionPagedQueryResponse;
"product-tailoring": ctp.ProductTailoringPagedQueryResponse;
"product-type": ctp.ProductTypePagedQueryResponse;
"product": ctp.ProductPagedQueryResponse;
"quote-request": ctp.QuoteRequestPagedQueryResponse;
Expand Down

0 comments on commit e50af4f

Please sign in to comment.