Skip to content

Commit

Permalink
feat: fix dal repo methods naming according to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sdlyy committed Mar 7, 2024
1 parent 889a097 commit 0bc4073
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe(OAppDefaultConfigurationRepository.name, () => {
})

describe(
OAppDefaultConfigurationRepository.prototype.findBySourceChain.name,
OAppDefaultConfigurationRepository.prototype.getBySourceChain.name,
() => {
it('returns only records with matching source chain', async () => {
const record1 = mockRecord({
Expand All @@ -61,7 +61,7 @@ describe(OAppDefaultConfigurationRepository.name, () => {

await repository.addMany([record1, record2, record3])

const result = await repository.findBySourceChain(ChainId.ETHEREUM)
const result = await repository.getBySourceChain(ChainId.ETHEREUM)

expect(result.length).toEqual(1)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class OAppDefaultConfigurationRepository extends BaseRepository {
return rows.map(toRecord)
}

public async findBySourceChain(
public async getBySourceChain(
sourceChainId: ChainId,
): Promise<OAppDefaultConfigurationRecord[]> {
const knex = await this.knex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ describe(OAppRepository.name, () => {

await repository.addMany([record1, record2])

const recordsBeforeMerge = await repository.findAll()
const recordsBeforeMerge = await repository.getAll()

await repository.addMany([record1, record2])

const recordsAfterMerge = await repository.findAll()
const recordsAfterMerge = await repository.getAll()

expect(recordsBeforeMerge.length).toEqual(2)
expect(recordsAfterMerge.length).toEqual(2)
})
})

describe(OAppRepository.prototype.findBySourceChain.name, () => {
describe(OAppRepository.prototype.getBySourceChain.name, () => {
it('returns only records with matching source chain', async () => {
const record1 = mockRecord({
id: 1,
Expand All @@ -51,7 +51,7 @@ describe(OAppRepository.name, () => {

await repository.addMany([record1, record2, record3])

const result = await repository.findBySourceChain(ChainId.ETHEREUM)
const result = await repository.getBySourceChain(ChainId.ETHEREUM)

expect(result.length).toEqual(1)
})
Expand Down
6 changes: 2 additions & 4 deletions packages/backend/src/peripherals/database/OAppRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ export class OAppRepository extends BaseRepository {
return ids.map((id) => id.id)
}

public async findAll(): Promise<OAppRecord[]> {
public async getAll(): Promise<OAppRecord[]> {
const knex = await this.knex()

const rows = await knex('oapp').select('*')

return rows.map(toRecord)
}

public async findBySourceChain(
sourceChainId: ChainId,
): Promise<OAppRecord[]> {
public async getBySourceChain(sourceChainId: ChainId): Promise<OAppRecord[]> {
const knex = await this.knex()

const rows = await knex('oapp')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class OAppConfigurationIndexer extends ChildIndexer {
}

protected override async update(_from: number, to: number): Promise<number> {
const oApps = await this.oAppRepo.findBySourceChain(this.chainId)
const oApps = await this.oAppRepo.getBySourceChain(this.chainId)

const configurationRecords = await Promise.all(
oApps.map(async (oApp) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/tracking/http/TrackingController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe(TrackingController.name, () => {
const oAppConfigRepo = mockObject<OAppConfigurationRepository>({})
const oAppDefaultConfigRepo =
mockObject<OAppDefaultConfigurationRepository>({
findBySourceChain: () => Promise.resolve([]),
getBySourceChain: () => Promise.resolve([]),
})

const controller = new TrackingController(
Expand Down Expand Up @@ -104,15 +104,15 @@ describe(TrackingController.name, () => {
]

const oAppRepo = mockObject<OAppRepository>({
findBySourceChain: () => Promise.resolve([oAppA, oAppB]),
getBySourceChain: () => Promise.resolve([oAppA, oAppB]),
})

const oAppConfigRepo = mockObject<OAppConfigurationRepository>({
findByOAppIds: () => Promise.resolve(mockConfigurations),
})
const oAppDefaultConfigRepo =
mockObject<OAppDefaultConfigurationRepository>({
findBySourceChain: (chainId) =>
getBySourceChain: (chainId) =>
Promise.resolve([
{
sourceChainId: chainId,
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/tracking/http/TrackingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class TrackingController {

async getOApps(chainId: ChainId): Promise<OAppsResponse | null> {
const defaultConfigurations =
await this.oAppDefaultConfigRepo.findBySourceChain(chainId)
await this.oAppDefaultConfigRepo.getBySourceChain(chainId)

if (defaultConfigurations.length === 0) {
return null
}

const oApps = await this.oAppRepo.findBySourceChain(chainId)
const oApps = await this.oAppRepo.getBySourceChain(chainId)

if (oApps.length === 0) {
return null
Expand Down

0 comments on commit 0bc4073

Please sign in to comment.