123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- import { Option, Text, u32 } from '@polkadot/types';
- import {
- AcceptingApplications,
- ActiveOpeningStage,
- ApplicationRationingPolicy,
- StakingPolicy,
- Opening, OpeningStage,
- ReviewPeriod,
- } from "@joystream/types/lib/hiring"
- import {
- OpeningState,
- IBlockQueryer,
- classifyOpeningStage, OpeningStageClassification,
- } from './classifiers'
- class mockBlockQueryer {
- hash: string
- timestamp: Date
- constructor(
- hash: string = "somehash",
- timestamp: Date = new Date(),
- ) {
- this.hash = hash
- this.timestamp = timestamp
- }
- async blockHash(height: number): Promise<string> {
- return this.hash
- }
- async blockTimestamp(height: number): Promise<Date> {
- return this.timestamp
- }
- async expectedBlockTime(): Promise<number> {
- return 6
- }
- }
- type Test = {
- description: string
- input: {
- queryer: IBlockQueryer,
- opening: Opening,
- }
- output: OpeningStageClassification
- }
- describe('hiring.Opening-> OpeningStageClassification', (): void => {
- const now = new Date("2020-01-23T11:47:04.433Z")
- const cases: Test[] = [
- {
- description: "WaitingToBegin",
- input: {
- opening: new Opening({
- created: new u32(100),
- stage: new OpeningStage({
- 'WaitingToBegin': {
- begins_at_block: new u32(100),
- }
- }),
- max_review_period_length: new u32(100),
- application_rationing_policy: new Option(ApplicationRationingPolicy),
- application_staking_policy: new Option(StakingPolicy),
- role_staking_policy: new Option(StakingPolicy),
- human_readable_text: new Text(),
- }),
- queryer: new mockBlockQueryer("somehash", now),
- },
- output: {
- state: OpeningState.WaitingToBegin,
- starting_block: 100,
- starting_block_hash: "somehash",
- starting_time: now,
- },
- },
- {
- description: "Accepting applications",
- input: {
- opening: new Opening({
- created: new u32(100),
- stage: new OpeningStage({
- 'Active': {
- stage: new ActiveOpeningStage({
- acceptingApplications: new AcceptingApplications({
- started_accepting_applicants_at_block: new u32(100),
- })
- })
- }
- }),
- max_review_period_length: new u32(100),
- application_rationing_policy: new Option(ApplicationRationingPolicy),
- application_staking_policy: new Option(StakingPolicy),
- role_staking_policy: new Option(StakingPolicy),
- human_readable_text: new Text(),
- }),
- queryer: new mockBlockQueryer("somehash", now),
- },
- output: {
- state: OpeningState.AcceptingApplications,
- starting_block: 100,
- starting_block_hash: "somehash",
- starting_time: now,
- },
- },
- {
- description: "In review period",
- input: {
- opening: new Opening({
- created: new u32(100),
- stage: new OpeningStage({
- 'Active': {
- stage: new ActiveOpeningStage({
- reviewPeriod: new ReviewPeriod({
- started_accepting_applicants_at_block: new u32(100),
- started_review_period_at_block: new u32(100),
- })
- })
- }
- }),
- max_review_period_length: new u32(14400),
- application_rationing_policy: new Option(ApplicationRationingPolicy),
- application_staking_policy: new Option(StakingPolicy),
- role_staking_policy: new Option(StakingPolicy),
- human_readable_text: new Text(),
- }),
- queryer: new mockBlockQueryer("somehash", now),
- },
- output: {
- state: OpeningState.InReview,
- starting_block: 100,
- starting_block_hash: "somehash",
- starting_time: now,
- review_end_block: 14500,
- review_end_time: new Date("2020-01-24T11:47:04.433Z"),
- },
- },
- /*
- * jest is having trouble with the enum type
- {
- description: "Deactivated: cancelled",
- input: {
- opening: new Opening({
- created: new u32(100),
- stage: new OpeningStage({
- 'Active': {
- stage: new ActiveOpeningStage({
- reviewPeriod: new Deactivated({
- cause: new OpeningDeactivationCause(
- OpeningDeactivationCauseKeys.CancelledBeforeActivation,
- ),
- deactivated_at_block: new u32(123),
- started_accepting_applicants_at_block: new u32(100),
- started_review_period_at_block: new Option(u32, 100),
- })
- })
- }
- }),
- max_review_period_length: new u32(100),
- application_rationing_policy: new Option(ApplicationRationingPolicy),
- application_staking_policy: new Option(StakingPolicy),
- role_staking_policy: new Option(StakingPolicy),
- human_readable_text: new Text(),
- }),
- queryer: new mockBlockQueryer("somehash", now),
- },
- output: {
- state: OpeningState.Cancelled,
- starting_block: 123,
- starting_block_hash: "somehash",
- starting_time: now,
- },
- },
- */
- ]
- cases.forEach((test: Test) => {
- it(test.description, async () => {
- expect(
- await classifyOpeningStage(
- test.input.queryer,
- test.input.opening,
- )
- ).toEqual(
- test.output
- )
- });
- })
- })
|