-
Notifications
You must be signed in to change notification settings - Fork 44
[Job Launcher][Server] JobService tests #3373
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
368b42e
- Created tests for JobService
flopez7 c847ad4
fix: remove audio duration from createAudinoJobDto
flopez7 79d3b93
simplify mocked provider and region retrieval in storage fixtures and…
flopez7 5ab4458
enhance getOracleType tests for job types with specific assertions
flopez7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../job-launcher/server/src/database/migrations/1748612934037-removeNullableFromJobEntity.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class RemoveNullableFromJobEntity1748612934037 | ||
| implements MigrationInterface | ||
| { | ||
| name = 'RemoveNullableFromJobEntity1748612934037'; | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| DROP INDEX "hmt"."IDX_59f6c552b618c432f019500e7c" | ||
| `); | ||
| await queryRunner.query(` | ||
| ALTER TABLE "hmt"."jobs" | ||
| ALTER COLUMN "chain_id" | ||
| SET NOT NULL | ||
| `); | ||
| await queryRunner.query(` | ||
| ALTER TABLE "hmt"."jobs" | ||
| ALTER COLUMN "reputation_oracle" | ||
| SET NOT NULL | ||
| `); | ||
| await queryRunner.query(` | ||
| ALTER TABLE "hmt"."jobs" | ||
| ALTER COLUMN "exchange_oracle" | ||
| SET NOT NULL | ||
| `); | ||
| await queryRunner.query(` | ||
| ALTER TABLE "hmt"."jobs" | ||
| ALTER COLUMN "recording_oracle" | ||
| SET NOT NULL | ||
| `); | ||
| await queryRunner.query(` | ||
| CREATE UNIQUE INDEX "IDX_59f6c552b618c432f019500e7c" ON "hmt"."jobs" ("chain_id", "escrow_address") | ||
| `); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| DROP INDEX "hmt"."IDX_59f6c552b618c432f019500e7c" | ||
| `); | ||
| await queryRunner.query(` | ||
| ALTER TABLE "hmt"."jobs" | ||
| ALTER COLUMN "recording_oracle" DROP NOT NULL | ||
| `); | ||
| await queryRunner.query(` | ||
| ALTER TABLE "hmt"."jobs" | ||
| ALTER COLUMN "exchange_oracle" DROP NOT NULL | ||
| `); | ||
| await queryRunner.query(` | ||
| ALTER TABLE "hmt"."jobs" | ||
| ALTER COLUMN "reputation_oracle" DROP NOT NULL | ||
| `); | ||
| await queryRunner.query(` | ||
| ALTER TABLE "hmt"."jobs" | ||
| ALTER COLUMN "chain_id" DROP NOT NULL | ||
| `); | ||
| await queryRunner.query(` | ||
| CREATE UNIQUE INDEX "IDX_59f6c552b618c432f019500e7c" ON "hmt"."jobs" ("chain_id", "escrow_address") | ||
| `); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
packages/apps/job-launcher/server/src/modules/job/fixtures.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| import { faker } from '@faker-js/faker'; | ||
| import { ChainId } from '@human-protocol/sdk'; | ||
| import { | ||
| getMockedProvider, | ||
| getMockedRegion, | ||
| } from '../../../test/fixtures/storage'; | ||
| import { | ||
| AudinoJobType, | ||
| CvatJobType, | ||
| EscrowFundToken, | ||
| FortuneJobType, | ||
| JobCaptchaShapeType, | ||
| } from '../../common/enums/job'; | ||
| import { PaymentCurrency } from '../../common/enums/payment'; | ||
| import { | ||
| JobAudinoDto, | ||
| JobCaptchaDto, | ||
| JobCvatDto, | ||
| JobFortuneDto, | ||
| } from './job.dto'; | ||
| import { JobEntity } from './job.entity'; | ||
| import { JobStatus } from '../../common/enums/job'; | ||
|
|
||
| export const createFortuneJobDto = (overrides = {}): JobFortuneDto => ({ | ||
| chainId: ChainId.POLYGON_AMOY, | ||
| submissionsRequired: faker.number.int({ min: 1, max: 10 }), | ||
| requesterTitle: faker.lorem.words(3), | ||
| requesterDescription: faker.lorem.sentence(), | ||
| paymentAmount: faker.number.float({ min: 1, max: 100, fractionDigits: 6 }), | ||
| paymentCurrency: faker.helpers.arrayElement(Object.values(PaymentCurrency)), | ||
| escrowFundToken: faker.helpers.arrayElement(Object.values(EscrowFundToken)), | ||
| exchangeOracle: faker.finance.ethereumAddress(), | ||
| recordingOracle: faker.finance.ethereumAddress(), | ||
| reputationOracle: faker.finance.ethereumAddress(), | ||
| ...overrides, | ||
| }); | ||
|
|
||
| export const createCvatJobDto = (overrides = {}): JobCvatDto => ({ | ||
| chainId: ChainId.POLYGON_AMOY, | ||
| data: { | ||
| dataset: { | ||
| provider: getMockedProvider(), | ||
| region: getMockedRegion(), | ||
| bucketName: faker.lorem.word(), | ||
| path: faker.system.filePath(), | ||
| }, | ||
| }, | ||
| labels: [{ name: faker.lorem.word(), nodes: [faker.string.uuid()] }], | ||
| requesterDescription: faker.lorem.sentence(), | ||
| userGuide: faker.internet.url(), | ||
| minQuality: faker.number.float({ min: 0.1, max: 1 }), | ||
| groundTruth: { | ||
| provider: getMockedProvider(), | ||
| region: getMockedRegion(), | ||
| bucketName: faker.lorem.word(), | ||
| path: faker.system.filePath(), | ||
| }, | ||
| type: faker.helpers.arrayElement(Object.values(CvatJobType)), | ||
| paymentCurrency: faker.helpers.arrayElement(Object.values(PaymentCurrency)), | ||
| paymentAmount: faker.number.int({ min: 1, max: 1000 }), | ||
| escrowFundToken: faker.helpers.arrayElement(Object.values(EscrowFundToken)), | ||
| exchangeOracle: faker.finance.ethereumAddress(), | ||
| recordingOracle: faker.finance.ethereumAddress(), | ||
| reputationOracle: faker.finance.ethereumAddress(), | ||
| ...overrides, | ||
| }); | ||
|
|
||
| export const createAudinoJobDto = (overrides = {}): JobAudinoDto => ({ | ||
| chainId: ChainId.POLYGON_AMOY, | ||
| data: { | ||
| dataset: { | ||
| provider: getMockedProvider(), | ||
| region: getMockedRegion(), | ||
| bucketName: faker.lorem.word(), | ||
| path: faker.system.filePath(), | ||
| }, | ||
| }, | ||
| groundTruth: { | ||
| provider: getMockedProvider(), | ||
| region: getMockedRegion(), | ||
| bucketName: faker.lorem.word(), | ||
| path: faker.system.filePath(), | ||
| }, | ||
| labels: [{ name: faker.lorem.word() }], | ||
| segmentDuration: faker.number.int({ min: 10, max: 100 }), | ||
| requesterDescription: faker.lorem.sentence(), | ||
| userGuide: faker.internet.url(), | ||
| qualifications: [faker.lorem.word()], | ||
| minQuality: faker.number.int({ min: 1, max: 100 }), | ||
| type: AudinoJobType.AUDIO_TRANSCRIPTION, | ||
| paymentCurrency: faker.helpers.arrayElement(Object.values(PaymentCurrency)), | ||
| paymentAmount: faker.number.int({ min: 1, max: 1000 }), | ||
| escrowFundToken: faker.helpers.arrayElement(Object.values(EscrowFundToken)), | ||
| exchangeOracle: faker.finance.ethereumAddress(), | ||
| recordingOracle: faker.finance.ethereumAddress(), | ||
| reputationOracle: faker.finance.ethereumAddress(), | ||
| ...overrides, | ||
| }); | ||
|
|
||
| export const createCaptchaJobDto = (overrides = {}): JobCaptchaDto => ({ | ||
| chainId: ChainId.POLYGON_AMOY, | ||
| data: { | ||
| provider: getMockedProvider(), | ||
| region: getMockedRegion(), | ||
| bucketName: faker.lorem.word(), | ||
| path: faker.system.filePath(), | ||
| }, | ||
| accuracyTarget: faker.number.float({ min: 0.1, max: 1, fractionDigits: 4 }), | ||
| minRequests: faker.number.int({ min: 1, max: 5 }), | ||
| maxRequests: faker.number.int({ min: 6, max: 10 }), | ||
| annotations: { | ||
| typeOfJob: faker.helpers.arrayElement(Object.values(JobCaptchaShapeType)), | ||
| labelingPrompt: faker.lorem.sentence(), | ||
| groundTruths: faker.internet.url(), | ||
| exampleImages: [faker.internet.url(), faker.internet.url()], | ||
| taskBidPrice: faker.number.float({ min: 0.1, max: 10, fractionDigits: 6 }), | ||
| label: faker.lorem.word(), | ||
| }, | ||
| completionDate: faker.date.future(), | ||
| paymentCurrency: faker.helpers.arrayElement(Object.values(PaymentCurrency)), | ||
| paymentAmount: faker.number.int({ min: 1, max: 1000 }), | ||
| escrowFundToken: faker.helpers.arrayElement(Object.values(EscrowFundToken)), | ||
| exchangeOracle: faker.finance.ethereumAddress(), | ||
| recordingOracle: faker.finance.ethereumAddress(), | ||
| reputationOracle: faker.finance.ethereumAddress(), | ||
| advanced: {}, | ||
| ...overrides, | ||
| }); | ||
|
|
||
| export const createJobEntity = ( | ||
| overrides: Partial<JobEntity> = {}, | ||
| ): JobEntity => { | ||
| const entity = new JobEntity(); | ||
| entity.id = faker.number.int(); | ||
| entity.chainId = ChainId.POLYGON_AMOY; | ||
| entity.reputationOracle = faker.finance.ethereumAddress(); | ||
| entity.exchangeOracle = faker.finance.ethereumAddress(); | ||
| entity.recordingOracle = faker.finance.ethereumAddress(); | ||
| entity.escrowAddress = faker.finance.ethereumAddress(); | ||
| entity.fee = faker.number.float({ min: 0.01, max: 1, fractionDigits: 6 }); | ||
| entity.fundAmount = faker.number.float({ | ||
| min: 1, | ||
| max: 1000, | ||
| fractionDigits: 6, | ||
| }); | ||
| entity.token = faker.helpers.arrayElement( | ||
| Object.values(EscrowFundToken), | ||
| ) as EscrowFundToken; | ||
| entity.manifestUrl = faker.internet.url(); | ||
| entity.manifestHash = faker.string.uuid(); | ||
| entity.failedReason = null; | ||
| entity.requestType = FortuneJobType.FORTUNE; | ||
| entity.status = faker.helpers.arrayElement(Object.values(JobStatus)); | ||
| entity.userId = faker.number.int(); | ||
| entity.payments = []; | ||
| entity.contentModerationRequests = []; | ||
| entity.retriesCount = faker.number.int({ min: 0, max: 4 }); | ||
| entity.waitUntil = faker.date.future(); | ||
| Object.assign(entity, overrides); | ||
| return entity; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.