Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only pass
data
from SaveOptions during that query (#7886)
this resets the `data` passed from `SaveOptions` to `QueryRunner` once the persistence operation has completed
- Loading branch information
1 parent
063aafa
commit 1de2e13
Showing
5 changed files
with
93 additions
and
9 deletions.
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
10 changes: 10 additions & 0 deletions
10
test/functional/entity-subscriber/query-data/entity/Example.ts
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,10 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../../src/"; | ||
|
||
@Entity() | ||
export class Example { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
value: number = 0; | ||
} |
61 changes: 61 additions & 0 deletions
61
test/functional/entity-subscriber/query-data/query-data.ts
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,61 @@ | ||
import { | ||
Connection, | ||
} from "../../../../src"; | ||
import {closeTestingConnections, createTestingConnections} from "../../../utils/test-utils"; | ||
import {expect} from "chai"; | ||
import { MockSubscriber } from "./subscribers/MockSubscriber"; | ||
import { Example } from "./entity/Example"; | ||
|
||
describe("entity subscriber > query data", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [ Example ], | ||
subscribers: [ MockSubscriber ], | ||
dropSchema: true, | ||
schemaCreate: true, | ||
enabledDrivers: [ "sqlite" ] | ||
})); | ||
beforeEach(() => { | ||
for (const connection of connections) { | ||
(connection.subscribers[0] as MockSubscriber).calledData.length = 0; | ||
} | ||
}) | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("passes query data to subscriber", () => Promise.all(connections.map(async connection => { | ||
const subscriber = connection.subscribers[0] as MockSubscriber; | ||
|
||
const example = new Example(); | ||
|
||
await connection.manager.save(example); | ||
|
||
example.value++; | ||
|
||
await connection.manager.save(example, { data: { Hello: "World" } }); | ||
|
||
expect(subscriber.calledData).to.be.eql([ | ||
{ Hello: "World" }, | ||
]); | ||
}))); | ||
|
||
it("cleans up the data after the save completes", () => Promise.all(connections.map(async connection => { | ||
const subscriber = connection.subscribers[0] as MockSubscriber; | ||
|
||
const example = new Example(); | ||
|
||
await connection.manager.save(example); | ||
|
||
example.value++; | ||
|
||
await connection.manager.save(example, { data: { Hello: "World" } }); | ||
|
||
example.value++; | ||
|
||
await connection.manager.save(example); | ||
|
||
expect(subscriber.calledData).to.be.eql([ | ||
{ Hello: "World" }, | ||
{}, | ||
]); | ||
}))); | ||
}); |
10 changes: 10 additions & 0 deletions
10
test/functional/entity-subscriber/query-data/subscribers/MockSubscriber.ts
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,10 @@ | ||
import { EntitySubscriberInterface, EventSubscriber, UpdateEvent } from "../../../../../src"; | ||
|
||
@EventSubscriber() | ||
export class MockSubscriber implements EntitySubscriberInterface { | ||
calledData: any[] = []; | ||
|
||
afterUpdate(event: UpdateEvent<any>): void { | ||
this.calledData.push(event.queryRunner.data); | ||
} | ||
} |
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