-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Correctly serialize job queue data payloads
Errors were arising in the EmailPlugin whereby the Order entity would be added to the job context and would be incorrectly serialized, leading to a `Cannot set property totalBeforeTax of #<Order> which has only a getter` error.
- Loading branch information
1 parent
c807d32
commit 1a9ac07
Showing
2 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,98 @@ | ||
import { Job } from './job'; | ||
|
||
describe('Job class', () => { | ||
describe('ensuring job data is serializable', () => { | ||
it('getters are converted to plain properties', () => { | ||
class Order { | ||
code = 123; | ||
get totalPrice() { | ||
return 42; | ||
} | ||
} | ||
|
||
const job = new Job({ | ||
queueName: 'test', | ||
data: new Order(), | ||
}); | ||
|
||
expect(job.data).toEqual({ | ||
code: 123, | ||
totalPrice: 42, | ||
}); | ||
}); | ||
|
||
it('getters are converted to plain properties (nested)', () => { | ||
class Order { | ||
code = 123; | ||
get totalPrice() { | ||
return 42; | ||
} | ||
} | ||
|
||
const data: any = { | ||
order: new Order(), | ||
}; | ||
|
||
const job = new Job({ | ||
queueName: 'test', | ||
data, | ||
}); | ||
|
||
expect(job.data).toEqual({ | ||
order: { | ||
code: 123, | ||
totalPrice: 42, | ||
}, | ||
}); | ||
}); | ||
|
||
it('getters are converted to plain properties (nested array)', () => { | ||
class Order { | ||
code = 123; | ||
get totalPrice() { | ||
return 42; | ||
} | ||
} | ||
|
||
const data: any = { | ||
orders: [new Order()], | ||
}; | ||
|
||
const job = new Job({ | ||
queueName: 'test', | ||
data, | ||
}); | ||
|
||
expect(job.data).toEqual({ | ||
orders: [ | ||
{ | ||
code: 123, | ||
totalPrice: 42, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('handles dates', () => { | ||
const date = new Date('2020-03-01T10:00:00Z'); | ||
|
||
const job = new Job({ | ||
queueName: 'test', | ||
data: date as any, | ||
}); | ||
|
||
expect(job.data).toEqual(date.toISOString()); | ||
}); | ||
|
||
it('handles dates (nested)', () => { | ||
const date = new Date('2020-03-01T10:00:00Z'); | ||
|
||
const job = new Job({ | ||
queueName: 'test', | ||
data: { createdAt: date as any }, | ||
}); | ||
|
||
expect(job.data).toEqual({ createdAt: date.toISOString() }); | ||
}); | ||
}); | ||
}); |
This file contains 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