chore(): Module Internal Events (#13296)
* chore(): Ensure the product module emits all necessary events * chore(): Ensure the product module emits all necessary events * Update events tests * more events and fixes * more tests and category fixes * more tests and category fixes * Add todo * update updateProduct_ event emitting and adjust test * Adjust update products implementation to rely on already computed events * rm unnecessary update variants events * Fix formatting in changeset for product events * refactor: Manage event emitting automatically (WIP) * refactor: Manage event emitting automatically (WIP) * chore(api-key): Add missing emit events and refactoring * chore(cart): Add missing emit events and refactoring * chore(customer): Add missing emit events and refactoring * chore(fufillment, utils): Add missing emit events and refactoring * chore(fufillment, utils): Add missing emit events and refactoring * chore(inventory): Add missing emit events and refactoring * chore(notification): Add missing emit events and refactoring * chore(utils): Remove medusa service event handling legacy * chore(product): Add missing emit events and refactoring * chore(order): Add missing emit events and refactoring * chore(payment): Add missing emit events and refactoring * chore(pricing, util): Add missing emit events and refactoring, fix internal service upsertWithReplace event dispatching * chore(promotions): Add missing emit events and refactoring * chore(region): Add missing emit events and refactoring * chore(sales-channel): Add missing emit events and refactoring * chore(settings): Add missing emit events and refactoring * chore(stock-location): Add missing emit events and refactoring * chore(store): Add missing emit events and refactoring * chore(taxes): Add missing emit events and refactoring * chore(user): Add missing emit events and refactoring * fix unit tests * rm changeset for regeneration * Create changeset for Medusa.js patch updates Add a changeset for patch updates to multiple Medusa.js modules. * rm unused product event builders * address feedback * remove old changeset * fix event action for token generated * fix user module events * fix import * fix promotion events * add new module integration tests shard * fix medusa service * revert shard * fix event action * fix pipeline * fix pipeline --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
afe21741c4
commit
e8822f3e69
@@ -172,17 +172,20 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
},
|
||||
])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
// 2 events: 1 invite updated, 1 invite token generated
|
||||
const events = eventBusSpy.mock.calls[0][0]
|
||||
expect(events).toHaveLength(2)
|
||||
expect(events).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_UPDATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -190,21 +193,25 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
describe("resendInvite", () => {
|
||||
it("should emit token generated event for invites", async () => {
|
||||
await service.createInvites(defaultInviteData)
|
||||
|
||||
const eventBusSpy = jest.spyOn(MockEventBusService.prototype, "emit")
|
||||
eventBusSpy.mockClear()
|
||||
|
||||
await service.refreshInviteTokens(["1"])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(2)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
const events = eventBusSpy.mock.calls[0][0]
|
||||
expect(events).toHaveLength(2)
|
||||
expect(events).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: UserEvents.INVITE_UPDATED,
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
expect.objectContaining({
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
data: { id: "1" },
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -251,21 +258,25 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
const eventBusSpy = jest.spyOn(MockEventBusService.prototype, "emit")
|
||||
await service.createInvites(defaultInviteData)
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
// 4 events: 2 invites created, 2 invite token generated
|
||||
const events = eventBusSpy.mock.calls[0][0]
|
||||
expect(events).toHaveLength(3)
|
||||
|
||||
expect(events).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
data: { id: ["1", "2"] },
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_CREATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "2" },
|
||||
name: UserEvents.INVITE_CREATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: ["1", "2"] },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -253,17 +253,22 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
const eventBusSpy = jest.spyOn(MockEventBusService.prototype, "emit")
|
||||
await service.createUsers(defaultUserData)
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
// 2 events: 2 user created
|
||||
expect(eventBusSpy.mock.calls[0][0]).toHaveLength(2)
|
||||
|
||||
const events = eventBusSpy.mock.calls[0][0]
|
||||
expect(events).toHaveLength(2)
|
||||
expect(events).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
data: { id: ["1", "2"] },
|
||||
data: { id: "1" },
|
||||
name: UserEvents.USER_CREATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
expect.objectContaining({
|
||||
data: { id: "2" },
|
||||
name: UserEvents.USER_CREATED,
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -95,7 +95,7 @@ export default class UserModuleService
|
||||
}
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
@InjectManager()
|
||||
async validateInviteToken(
|
||||
token: string,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -129,9 +129,7 @@ export default class UserModuleService
|
||||
)
|
||||
}
|
||||
|
||||
return await this.baseRepository_.serialize<UserTypes.InviteDTO>(invite, {
|
||||
populate: true,
|
||||
})
|
||||
return await this.baseRepository_.serialize<UserTypes.InviteDTO>(invite)
|
||||
}
|
||||
|
||||
@InjectManager()
|
||||
@@ -142,22 +140,21 @@ export default class UserModuleService
|
||||
): Promise<UserTypes.InviteDTO[]> {
|
||||
const invites = await this.refreshInviteTokens_(inviteIds, sharedContext)
|
||||
|
||||
const serializedInvites = await this.baseRepository_.serialize<
|
||||
UserTypes.InviteDTO[]
|
||||
>(invites)
|
||||
|
||||
moduleEventBuilderFactory({
|
||||
eventName: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
source: Modules.USER,
|
||||
action: "token_generated",
|
||||
action: CommonEvents.CREATED,
|
||||
object: "invite",
|
||||
})({
|
||||
data: invites,
|
||||
data: serializedInvites,
|
||||
sharedContext,
|
||||
})
|
||||
|
||||
return await this.baseRepository_.serialize<UserTypes.InviteDTO[]>(
|
||||
invites,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
return serializedInvites
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
@@ -221,19 +218,7 @@ export default class UserModuleService
|
||||
|
||||
const serializedUsers = await this.baseRepository_.serialize<
|
||||
UserTypes.UserDTO[] | UserTypes.UserDTO
|
||||
>(users, {
|
||||
populate: true,
|
||||
})
|
||||
|
||||
moduleEventBuilderFactory({
|
||||
eventName: UserEvents.USER_CREATED,
|
||||
source: Modules.USER,
|
||||
action: CommonEvents.CREATED,
|
||||
object: "user",
|
||||
})({
|
||||
data: serializedUsers,
|
||||
sharedContext,
|
||||
})
|
||||
>(users)
|
||||
|
||||
return Array.isArray(data) ? serializedUsers : serializedUsers[0]
|
||||
}
|
||||
@@ -262,19 +247,7 @@ export default class UserModuleService
|
||||
|
||||
const serializedUsers = await this.baseRepository_.serialize<
|
||||
UserTypes.UserDTO[]
|
||||
>(updatedUsers, {
|
||||
populate: true,
|
||||
})
|
||||
|
||||
moduleEventBuilderFactory({
|
||||
eventName: UserEvents.USER_UPDATED,
|
||||
source: Modules.USER,
|
||||
action: CommonEvents.UPDATED,
|
||||
object: "user",
|
||||
})({
|
||||
data: serializedUsers,
|
||||
sharedContext,
|
||||
})
|
||||
>(updatedUsers)
|
||||
|
||||
return Array.isArray(data) ? serializedUsers : serializedUsers[0]
|
||||
}
|
||||
@@ -303,19 +276,7 @@ export default class UserModuleService
|
||||
|
||||
const serializedInvites = await this.baseRepository_.serialize<
|
||||
UserTypes.InviteDTO[] | UserTypes.InviteDTO
|
||||
>(invites, {
|
||||
populate: true,
|
||||
})
|
||||
|
||||
moduleEventBuilderFactory({
|
||||
eventName: UserEvents.INVITE_CREATED,
|
||||
source: Modules.USER,
|
||||
action: CommonEvents.CREATED,
|
||||
object: "invite",
|
||||
})({
|
||||
data: serializedInvites,
|
||||
sharedContext,
|
||||
})
|
||||
>(invites)
|
||||
|
||||
moduleEventBuilderFactory({
|
||||
eventName: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
@@ -390,14 +351,12 @@ export default class UserModuleService
|
||||
|
||||
const serializedInvites = await this.baseRepository_.serialize<
|
||||
UserTypes.InviteDTO[]
|
||||
>(updatedInvites, {
|
||||
populate: true,
|
||||
})
|
||||
>(updatedInvites)
|
||||
|
||||
moduleEventBuilderFactory({
|
||||
eventName: UserEvents.INVITE_UPDATED,
|
||||
eventName: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
source: Modules.USER,
|
||||
action: CommonEvents.UPDATED,
|
||||
action: "token_generated",
|
||||
object: "invite",
|
||||
})({
|
||||
data: serializedInvites,
|
||||
|
||||
Reference in New Issue
Block a user