Skip to content

Commit aea1ebb

Browse files
fix: narrow response type in test and fix ErrorBoundary error format
Amp-Thread-ID: https://ampcode.com/threads/T-019ca09b-2eda-7357-9a28-71f3648d5c02 Co-authored-by: Amp <amp@ampcode.com>
1 parent c37554a commit aea1ebb

2 files changed

Lines changed: 9 additions & 17 deletions

File tree

app/routes/__tests__/dashboard.transactions.$transactionId.$action.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ describe('dashboard.transactions.$transactionId.$action action', () => {
8787
expect(error).toBeInstanceOf(Response)
8888
const response = error as Response
8989
expect(response.status).toBe(400)
90-
await expect(response.json()).resolves.toMatchObject({
91-
formError: 'Status transaksi tidak valid.',
92-
})
90+
await expect(response.json()).resolves.toBe(
91+
'Status transaksi tidak valid.'
92+
)
9393
}
9494

9595
expect(updateTransactionStatus).not.toHaveBeenCalled()
@@ -109,10 +109,9 @@ describe('dashboard.transactions.$transactionId.$action action', () => {
109109
expect(error).toBeInstanceOf(Response)
110110
const response = error as Response
111111
expect(response.status).toBe(400)
112-
await expect(response.json()).resolves.toMatchObject({
113-
formError:
114-
'Transaksi yang sudah diverifikasi tidak dapat diubah menjadi ditolak.',
115-
})
112+
await expect(response.json()).resolves.toBe(
113+
'Transaksi yang sudah diverifikasi tidak dapat diubah menjadi ditolak.'
114+
)
116115
}
117116

118117
expect(updateTransactionStatus).not.toHaveBeenCalled()
@@ -122,6 +121,7 @@ describe('dashboard.transactions.$transactionId.$action action', () => {
122121
const response = await runAction(TRANSACTION_STATUS.VERIFIED)
123122

124123
expect(response).toBeInstanceOf(Response)
124+
if (!(response instanceof Response)) throw new Error('Expected Response')
125125
expect(response.status).toBe(302)
126126
expect(response.headers.get('Location')).toBe(
127127
'/dashboard/transactions/tx-1'

app/routes/dashboard.transactions.$transactionId.$action.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,7 @@ export const action: ActionFunction = async ({ request, params }) => {
8080
status !== TRANSACTION_STATUS.VERIFIED &&
8181
status !== TRANSACTION_STATUS.REJECTED
8282
) {
83-
throw json(
84-
{
85-
formError: 'Status transaksi tidak valid.',
86-
},
87-
{ status: 400 }
88-
)
83+
throw json('Status transaksi tidak valid.', { status: 400 })
8984
}
9085

9186
const existingTransaction = await getTransactionById(transactionId)
@@ -100,10 +95,7 @@ export const action: ActionFunction = async ({ request, params }) => {
10095
)
10196
) {
10297
throw json(
103-
{
104-
formError:
105-
'Transaksi yang sudah diverifikasi tidak dapat diubah menjadi ditolak.',
106-
},
98+
'Transaksi yang sudah diverifikasi tidak dapat diubah menjadi ditolak.',
10799
{ status: 400 }
108100
)
109101
}

0 commit comments

Comments
 (0)