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

Add methods to bull #151

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
5 changes: 5 additions & 0 deletions .changeset/dry-owls-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zemble/bull": patch
---

added getDelayed to ZembleQueueMock
7 changes: 7 additions & 0 deletions packages/bull/ZembleQueueMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface IZembleQueue<DataType = unknown, ReturnType = unknown> {
readonly resume: ZembleQueueBull<DataType, ReturnType>['resume']
readonly pause: ZembleQueueBull<DataType, ReturnType>['pause']
readonly waitUntilEmpty: ZembleQueueBull<DataType, ReturnType>['waitUntilEmpty']
readonly getDelayed: ZembleQueueBull<DataType, ReturnType>['getDelayed']
}

class ZembleQueueMock<DataType = unknown, ResultType extends PromiseLike<unknown> = PromiseLike<unknown>> implements IZembleQueue<DataType, ResultType> {
Expand All @@ -38,6 +39,7 @@ class ZembleQueueMock<DataType = unknown, ResultType extends PromiseLike<unknown
this.getJob = jest.fn(this.getJob.bind(this))
this.pause = jest.fn(this.pause.bind(this))
this.resume = jest.fn(this.resume.bind(this))
this.getDelayed = jest.fn(this.getDelayed.bind(this))
}

readonly #worker: ZembleWorker
Expand Down Expand Up @@ -136,6 +138,11 @@ class ZembleQueueMock<DataType = unknown, ResultType extends PromiseLike<unknown
this.isPaused = false
}

// eslint-disable-next-line class-methods-use-this
async getDelayed() {
return []
}
Comment on lines +141 to +144
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider enhancing the mock implementation.

The current implementation has several areas for improvement:

  1. The empty array return value might not accurately represent delayed jobs in the queue
  2. The eslint-disable comment seems unnecessary for an async method
  3. Missing documentation to explain the implementation choice

Consider this enhanced implementation:

-  // eslint-disable-next-line class-methods-use-this
-  async getDelayed() {
-    return []
-  }
+  /**
+   * Gets delayed jobs from the mock queue.
+   * @returns Array of delayed jobs based on JobsOptions.delay
+   */
+  async getDelayed() {
+    return this.jobs.filter(job => 
+      job.opts?.delay !== undefined && 
+      job.opts.delay > 0
+    )
+  }

This implementation would:

  • Return actual delayed jobs based on their options
  • Remove unnecessary eslint comment
  • Add documentation
  • Better mirror the real Bull queue behavior

Committable suggestion skipped: line range outside the PR's diff.


#waitUntilFinishedPromise: Promise<void> | undefined

#waitUntilFinishedResolver: ((value: void | PromiseLike<void>) => void) | undefined
Expand Down
4 changes: 1 addition & 3 deletions packages/push-apple/graphql/schema.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type Scalars = {
Boolean: { input: boolean; output: boolean; }
Int: { input: number; output: number; }
Float: { input: number; output: number; }
/** The `JSONObject` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf). */
JSONObject: { input: any; output: any; }
};

Expand Down Expand Up @@ -73,7 +72,6 @@ export type MutationRegisterAppleUpdateLiveActivityPushTokenArgs = {
activityId: Scalars['ID']['input'];
appBundleId: Scalars['String']['input'];
isSandbox?: InputMaybe<Scalars['Boolean']['input']>;
liveActivityAttributes: Scalars['JSONObject']['input'];
liveActivityType: Scalars['String']['input'];
token: Scalars['String']['input'];
};
Expand Down Expand Up @@ -218,7 +216,7 @@ export type MutationResolvers<ContextType = Zemble.GraphQLContext, ParentType ex
appleLiveActivityStateUpdated?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationAppleLiveActivityStateUpdatedArgs, 'activityId' | 'liveActivityType' | 'state'>>;
registerApplePushToken?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationRegisterApplePushTokenArgs, 'appBundleId' | 'platform' | 'token'>>;
registerAppleStartLiveActivityPushToken?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationRegisterAppleStartLiveActivityPushTokenArgs, 'appBundleId' | 'token'>>;
registerAppleUpdateLiveActivityPushToken?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationRegisterAppleUpdateLiveActivityPushTokenArgs, 'activityId' | 'appBundleId' | 'liveActivityAttributes' | 'liveActivityType' | 'token'>>;
registerAppleUpdateLiveActivityPushToken?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationRegisterAppleUpdateLiveActivityPushTokenArgs, 'activityId' | 'appBundleId' | 'liveActivityType' | 'token'>>;
sendPushNotification?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationSendPushNotificationArgs, 'body' | 'pushToken'>>;
sendSilentPushNotification?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationSendSilentPushNotificationArgs, 'data' | 'pushToken'>>;
startLiveActivity?: Resolver<ResolversTypes['StartLiveActivityResponse'], ParentType, ContextType, RequireFields<MutationStartLiveActivityArgs, 'data' | 'liveActivityType' | 'pushToken'>>;
Expand Down
39 changes: 0 additions & 39 deletions packages/push-expo/graphql/schema.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export enum ExpoPushPlatform {

export type Mutation = {
readonly __typename?: 'Mutation';
readonly randomNumber: Scalars['Int']['output'];
readonly registerExpoPushToken: Scalars['Boolean']['output'];
readonly sendPushNotification: Scalars['Boolean']['output'];
};
Expand All @@ -44,23 +43,6 @@ export type MutationSendPushNotificationArgs = {
title: Scalars['String']['input'];
};

export type Query = {
readonly __typename?: 'Query';
readonly hello: Scalars['String']['output'];
};

export type Subscription = {
readonly __typename?: 'Subscription';
readonly countdown: Scalars['Int']['output'];
readonly randomNumber: Scalars['Int']['output'];
readonly tick: Scalars['Float']['output'];
};


export type SubscriptionCountdownArgs = {
from: Scalars['Int']['input'];
};

export type WithIndex<TObject> = TObject & Record<string, any>;
export type ResolversObject<TObject> = WithIndex<TObject>;

Expand Down Expand Up @@ -135,44 +117,23 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
export type ResolversTypes = ResolversObject<{
Boolean: ResolverTypeWrapper<Scalars['Boolean']['output']>;
ExpoPushPlatform: ExpoPushPlatform;
Float: ResolverTypeWrapper<Scalars['Float']['output']>;
Int: ResolverTypeWrapper<Scalars['Int']['output']>;
Mutation: ResolverTypeWrapper<{}>;
Query: ResolverTypeWrapper<{}>;
String: ResolverTypeWrapper<Scalars['String']['output']>;
Subscription: ResolverTypeWrapper<{}>;
}>;

/** Mapping between all available schema types and the resolvers parents */
export type ResolversParentTypes = ResolversObject<{
Boolean: Scalars['Boolean']['output'];
Float: Scalars['Float']['output'];
Int: Scalars['Int']['output'];
Mutation: {};
Query: {};
String: Scalars['String']['output'];
Subscription: {};
}>;

export type MutationResolvers<ContextType = Zemble.GraphQLContext, ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation']> = ResolversObject<{
randomNumber?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
registerExpoPushToken?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationRegisterExpoPushTokenArgs, 'platform' | 'pushToken'>>;
sendPushNotification?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationSendPushNotificationArgs, 'body' | 'pushToken' | 'title'>>;
}>;

export type QueryResolvers<ContextType = Zemble.GraphQLContext, ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query']> = ResolversObject<{
hello?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
}>;

export type SubscriptionResolvers<ContextType = Zemble.GraphQLContext, ParentType extends ResolversParentTypes['Subscription'] = ResolversParentTypes['Subscription']> = ResolversObject<{
countdown?: SubscriptionResolver<ResolversTypes['Int'], "countdown", ParentType, ContextType, RequireFields<SubscriptionCountdownArgs, 'from'>>;
randomNumber?: SubscriptionResolver<ResolversTypes['Int'], "randomNumber", ParentType, ContextType>;
tick?: SubscriptionResolver<ResolversTypes['Float'], "tick", ParentType, ContextType>;
}>;

export type Resolvers<ContextType = Zemble.GraphQLContext> = ResolversObject<{
Mutation?: MutationResolvers<ContextType>;
Query?: QueryResolvers<ContextType>;
Subscription?: SubscriptionResolvers<ContextType>;
}>;

Loading