Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test changing index #422

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/repositories/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,16 @@ export interface BaseOrdersRepository<T extends OrderEntityType> {
txHash?: string,
settledAmounts?: SettledAmount[]
) => Promise<void>
updateOrder: (orderHash: string, entity: T) => Promise<void>
deleteOrders: (orderHashes: string[]) => Promise<void>
queryOrderEntity(
partitionKey: string | number,
index: string,
limit: number | undefined,
cursor?: string,
sortKey?: SORT_FIELDS | undefined,
sort?: string | undefined, // ex gt(123)
desc?: boolean,
filters?: { or: boolean; attr: string; eq: string }[]
): Promise<QueryResult<T>>
}
20 changes: 19 additions & 1 deletion lib/repositories/generic-orders-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export abstract class GenericOrdersRepository<
}
}

private async queryOrderEntity(
public async queryOrderEntity(
partitionKey: string | number,
index: string,
limit: number | undefined,
Expand Down Expand Up @@ -271,4 +271,22 @@ export abstract class GenericOrdersRepository<

return lastEvaluatedKey
}

public async updateOrder(orderHash: string, entity: T): Promise<void> {
try {
const order = checkDefined(
await this.getByHash(orderHash),
'cannot find order by hash when updating order status'
)

await this.entity.update({
...order, //any missed fields
...entity,
[TABLE_KEY.ORDER_HASH]: orderHash,
})
} catch (e) {
log.error('updateOrderStatus error', { error: e })
throw e
}
}
}
27 changes: 27 additions & 0 deletions test/integ/repositories/dynamo-repository.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { DocumentClient } from 'aws-sdk/clients/dynamodb'
import { TABLE_KEY } from '../../../lib/config/dynamodb'
import { ORDER_STATUS, SettledAmount, SORT_FIELDS, UniswapXOrderEntity } from '../../../lib/entities/Order'
import { GetOrderTypeQueryParamEnum } from '../../../lib/handlers/get-orders/schema/GetOrderTypeQueryParamEnum'
import { DutchV1Order } from '../../../lib/models'
import { DutchOrdersRepository } from '../../../lib/repositories/dutch-orders-repository'
import { ChainId } from '../../../lib/util/chain'
import { generateRandomNonce } from '../../../lib/util/nonce'
import { currentTimestampInSeconds } from '../../../lib/util/time'
import { SDKDutchOrderFactory } from '../../factories/SDKDutchOrderV1Factory'
import { deleteAllRepoEntries } from './deleteAllRepoEntries'

jest.mock('../../../lib/util/time')
Expand Down Expand Up @@ -571,6 +575,29 @@
})
})

it.only('should successfully update index with orderType', async () => {

Check failure on line 578 in test/integ/repositories/dynamo-repository.test.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

Unexpected focused test
const newOrder = new DutchV1Order(SDKDutchOrderFactory.buildDutchOrder(), 'signature', ChainId.MAINNET)
await ordersRepository.putOrderAndUpdateNonceTransaction(newOrder.toEntity(ORDER_STATUS.OPEN))
const firstResponse = await ordersRepository.getByHash(newOrder.inner.hash())

await ordersRepository.updateOrder(firstResponse!.orderHash, {
...firstResponse,
chainId_orderStatus: `${firstResponse?.chainId}_${firstResponse?.orderStatus}_${firstResponse?.type}`,
} as any)

const secondResponse = await ordersRepository.queryOrderEntity(
`${firstResponse?.chainId}_${firstResponse?.orderStatus}_${firstResponse?.type}`, //partitionKey:
`${TABLE_KEY.CHAIN_ID}_${TABLE_KEY.ORDER_STATUS}`, //index:
5, //limit:
undefined, //cursor:
undefined, // sortKey:
undefined, //sort:
true //desc:
)
expect(secondResponse.orders).toHaveLength(1)
expect(secondResponse.orders[0]).toEqual({ ...firstResponse, chainId_orderStatus: '1_open_Dutch' })
})

it('should throw error if order does not exist', async () => {
await expect(ordersRepository.updateOrderStatus('nonexistent', ORDER_STATUS.FILLED)).rejects.toEqual(
new Error('cannot find order by hash when updating order status')
Expand Down
Loading