Skip to content

Commit

Permalink
fix: test - Bull: should schedule a new job
Browse files Browse the repository at this point in the history
  • Loading branch information
RodolfoSilva committed Sep 6, 2020
1 parent 32ea216 commit bb8f3d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion npm-audit.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h5 class="card-title">
<div class="card">
<div class="card-body">
<h5 class="card-title">
September 6th 2020, 9:12:02 pm
September 6th 2020, 9:18:49 pm
</h5>
<p class="card-text">Last updated</p>
</div>
Expand Down
38 changes: 23 additions & 15 deletions test/unit/queue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,35 @@ test.group('Bull', () => {
test('should schedule a new job', async (assert) => {
const ioc = new Ioc()

ioc.bind('App/Jobs/TestBull', () => {
return class {
public queueName = 'TestBull-name'

public async handle() {}
}
})
ioc.bind('App/Jobs/TestBull', () => ({
queueName: 'TestBull-name',
async handle() {},
}))

ioc.bind('Adonis/Core/Logger', () => new FakeLogger({} as any))
ioc.bind('Adonis/Addons/Redis', () => new RedisManager(ioc, {} as any, {} as any))
const redis = (new RedisManager(
ioc,
{
connection: 'primary',
connections: {
primary: {
host: process.env.REDIS_HOST,
port: Number(process.env.REDIS_PORT),
healthCheck: true,
},
},
} as any,
new Emitter(ioc)
) as unknown) as RedisManagerContract

const loggerInstance = ioc.use('Adonis/Core/Logger')
const Redis = ioc.use('Adonis/Addons/Redis')
const logger = (new FakeLogger({} as any) as unknown) as LoggerContract

const bull = new BullManager(ioc, loggerInstance, Redis, ['App/Jobs/TestBull'])
const Job = ioc.use('App/Jobs/TestBull')
const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull'])
const jobDefinition = ioc.use('App/Jobs/TestBull')
const data = { test: 'data' }

const job = await bull.schedule(Job.key, data, 1000)
const job = await bull.schedule(jobDefinition.queueName, data, 1000)

assert.equal(Job.key, job.name)
assert.equal(jobDefinition.queueName, job.name)
assert.equal(job.opts.delay, 1000)
assert.deepEqual(data, job.data)
})
Expand Down

0 comments on commit bb8f3d1

Please sign in to comment.