feat: Remove fields from payment models that were leftovers from v1 (#10987)
This commit is contained in:
@@ -2,19 +2,16 @@ export const defaultPaymentCollectionData = [
|
||||
{
|
||||
id: "pay-col-id-1",
|
||||
amount: 100,
|
||||
region_id: "region-id-1",
|
||||
currency_code: "usd",
|
||||
},
|
||||
{
|
||||
id: "pay-col-id-2",
|
||||
amount: 200,
|
||||
region_id: "region-id-1",
|
||||
currency_code: "usd",
|
||||
},
|
||||
{
|
||||
id: "pay-col-id-3",
|
||||
amount: 300,
|
||||
region_id: "region-id-2",
|
||||
currency_code: "usd",
|
||||
},
|
||||
]
|
||||
|
||||
@@ -15,7 +15,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
.createPaymentCollections([
|
||||
{
|
||||
amount: 200,
|
||||
region_id: "req_123",
|
||||
} as any,
|
||||
])
|
||||
.catch((e) => e)
|
||||
@@ -28,7 +27,7 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
it("should create a payment collection successfully", async () => {
|
||||
const [createdPaymentCollection] =
|
||||
await service.createPaymentCollections([
|
||||
{ currency_code: "USD", amount: 200, region_id: "reg_123" },
|
||||
{ currency_code: "USD", amount: 200 },
|
||||
])
|
||||
|
||||
expect(createdPaymentCollection).toEqual(
|
||||
|
||||
+1
-57
@@ -90,7 +90,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
let paymentCollection = await service.createPaymentCollections({
|
||||
currency_code: "usd",
|
||||
amount: 200,
|
||||
region_id: "reg_123",
|
||||
})
|
||||
|
||||
const paymentSession = await service.createPaymentSession(
|
||||
@@ -134,7 +133,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
authorized_amount: 200,
|
||||
captured_amount: 200,
|
||||
status: "authorized",
|
||||
region_id: "reg_123",
|
||||
deleted_at: null,
|
||||
completed_at: expect.any(Date),
|
||||
payment_sessions: [
|
||||
@@ -180,7 +178,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
.createPaymentCollections([
|
||||
{
|
||||
amount: 200,
|
||||
region_id: "req_123",
|
||||
} as any,
|
||||
])
|
||||
.catch((e) => e)
|
||||
@@ -193,7 +190,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
.createPaymentCollections([
|
||||
{
|
||||
currency_code: "USD",
|
||||
region_id: "req_123",
|
||||
} as any,
|
||||
])
|
||||
.catch((e) => e)
|
||||
@@ -202,25 +198,12 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
expect(error.message).toContain(
|
||||
"Value for PaymentCollection.amount is required, 'undefined' found"
|
||||
)
|
||||
|
||||
error = await service
|
||||
.createPaymentCollections([
|
||||
{
|
||||
currency_code: "USD",
|
||||
amount: 200,
|
||||
} as any,
|
||||
])
|
||||
.catch((e) => e)
|
||||
|
||||
expect(error.message).toContain(
|
||||
"Value for PaymentCollection.region_id is required, 'undefined' found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a payment collection successfully", async () => {
|
||||
const [createdPaymentCollection] =
|
||||
await service.createPaymentCollections([
|
||||
{ currency_code: "USD", amount: 200, region_id: "reg_123" },
|
||||
{ currency_code: "USD", amount: 200 },
|
||||
])
|
||||
|
||||
expect(createdPaymentCollection).toEqual(
|
||||
@@ -265,7 +248,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
expect.objectContaining({
|
||||
id: "pay-col-id-2",
|
||||
amount: 200,
|
||||
region_id: "region-id-1",
|
||||
currency_code: "usd",
|
||||
})
|
||||
)
|
||||
@@ -294,57 +276,27 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
expect.objectContaining({
|
||||
id: "pay-col-id-1",
|
||||
amount: 100,
|
||||
region_id: "region-id-1",
|
||||
currency_code: "usd",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "pay-col-id-2",
|
||||
amount: 200,
|
||||
region_id: "region-id-1",
|
||||
currency_code: "usd",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "pay-col-id-3",
|
||||
amount: 300,
|
||||
region_id: "region-id-2",
|
||||
currency_code: "usd",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("should list Payment Collections by region_id", async () => {
|
||||
let collections = await service.listPaymentCollections(
|
||||
{
|
||||
region_id: "region-id-1",
|
||||
},
|
||||
{ select: ["id", "amount", "region_id"] }
|
||||
)
|
||||
|
||||
expect(collections.length).toEqual(2)
|
||||
|
||||
expect(collections).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "pay-col-id-1",
|
||||
amount: 100,
|
||||
region_id: "region-id-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "pay-col-id-2",
|
||||
amount: 200,
|
||||
region_id: "region-id-1",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
it("should update a Payment Collection", async () => {
|
||||
await service.updatePaymentCollections("pay-col-id-2", {
|
||||
currency_code: "eur",
|
||||
region_id: "reg-2",
|
||||
})
|
||||
|
||||
const collection = await service.retrievePaymentCollection(
|
||||
@@ -354,7 +306,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
expect(collection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "pay-col-id-2",
|
||||
region_id: "reg-2",
|
||||
currency_code: "eur",
|
||||
})
|
||||
)
|
||||
@@ -545,7 +496,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
it("should authorize a payment session", async () => {
|
||||
const collection = await service.createPaymentCollections({
|
||||
amount: 200,
|
||||
region_id: "test-region",
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
@@ -576,9 +526,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
refunds: [],
|
||||
captures: [],
|
||||
data: {},
|
||||
cart_id: null,
|
||||
order_id: null,
|
||||
customer_id: null,
|
||||
deleted_at: null,
|
||||
captured_at: null,
|
||||
canceled_at: null,
|
||||
@@ -615,13 +562,11 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
it("should update a payment successfully", async () => {
|
||||
const updatedPayment = await service.updatePayment({
|
||||
id: "pay-id-1",
|
||||
cart_id: "new-cart",
|
||||
})
|
||||
|
||||
expect(updatedPayment).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "pay-id-1",
|
||||
cart_id: "new-cart",
|
||||
})
|
||||
)
|
||||
})
|
||||
@@ -908,7 +853,6 @@ moduleIntegrationTestRunner<IPaymentModuleService>({
|
||||
it("should authorize, capture and refund multiple payment sessions", async () => {
|
||||
const collection = await service.createPaymentCollections({
|
||||
amount: 500,
|
||||
region_id: "test-region",
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
|
||||
@@ -60,15 +60,6 @@
|
||||
"nullable": true,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"region_id": {
|
||||
"name": "region_id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"completed_at": {
|
||||
"name": "completed_at",
|
||||
"type": "timestamptz",
|
||||
@@ -185,14 +176,6 @@
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_payment_collection_deleted_at\" ON \"payment_collection\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_payment_collection_region_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_payment_collection_region_id\" ON \"payment_collection\" (region_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "payment_collection_pkey",
|
||||
"columnNames": [
|
||||
@@ -700,33 +683,6 @@
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"cart_id": {
|
||||
"name": "cart_id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"order_id": {
|
||||
"name": "order_id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"customer_id": {
|
||||
"name": "customer_id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"data": {
|
||||
"name": "data",
|
||||
"type": "jsonb",
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20250115160517 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_payment_collection_region_id";');
|
||||
this.addSql('alter table if exists "payment_collection" drop column if exists "region_id";');
|
||||
|
||||
this.addSql('alter table if exists "payment" drop column if exists "cart_id";');
|
||||
this.addSql('alter table if exists "payment" drop column if exists "order_id";');
|
||||
this.addSql('alter table if exists "payment" drop column if exists "customer_id";');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('alter table if exists "payment_collection" add column if not exists "region_id" text not null;');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_payment_collection_region_id" ON "payment_collection" (region_id) WHERE deleted_at IS NULL;');
|
||||
|
||||
this.addSql('alter table if exists "payment" add column if not exists "cart_id" text null, add column if not exists "order_id" text null, add column if not exists "customer_id" text null;');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,6 @@ const PaymentCollection = model
|
||||
authorized_amount: model.bigNumber().nullable(),
|
||||
captured_amount: model.bigNumber().nullable(),
|
||||
refunded_amount: model.bigNumber().nullable(),
|
||||
region_id: model.text(),
|
||||
completed_at: model.dateTime().nullable(),
|
||||
status: model
|
||||
.enum(PaymentCollectionStatus)
|
||||
@@ -30,11 +29,5 @@ const PaymentCollection = model
|
||||
.cascades({
|
||||
delete: ["payment_sessions", "payments"],
|
||||
})
|
||||
.indexes([
|
||||
{
|
||||
name: "IDX_payment_collection_region_id",
|
||||
on: ["region_id"],
|
||||
},
|
||||
])
|
||||
|
||||
export default PaymentCollection
|
||||
|
||||
@@ -10,9 +10,6 @@ const Payment = model
|
||||
amount: model.bigNumber(),
|
||||
currency_code: model.text(),
|
||||
provider_id: model.text(),
|
||||
cart_id: model.text().searchable().nullable(),
|
||||
order_id: model.text().searchable().nullable(),
|
||||
customer_id: model.text().searchable().nullable(),
|
||||
data: model.json().nullable(),
|
||||
metadata: model.json().nullable(),
|
||||
captured_at: model.dateTime().nullable(),
|
||||
|
||||
Reference in New Issue
Block a user