-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve issue delete column null on after update event subscriber (
- Loading branch information
1 parent
d494fcc
commit 8a5e671
Showing
6 changed files
with
83 additions
and
5 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
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
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
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,13 @@ | ||
import { DeleteDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "../../../../src"; | ||
|
||
@Entity() | ||
export class Post { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@UpdateDateColumn() | ||
updatedAt: Date; | ||
|
||
@DeleteDateColumn() | ||
deletedAt: Date; | ||
} |
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,31 @@ | ||
import "reflect-metadata"; | ||
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { Post } from "./entity/Post"; | ||
|
||
describe("github issues > #6327 softRemove DeleteDateColumn is null at Susbscriber's AfterUpdate method", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
subscribers: [__dirname + "/subscriber/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should send correct update and delete date columns to after update subscriber", () => Promise.all(connections.map(async connection => { | ||
|
||
const manager = connection.manager; | ||
|
||
const entity = new Post(); | ||
await manager.save(entity); | ||
|
||
const deletedEntity = await manager.softRemove(entity, { data: { action: "soft-delete" } }); | ||
|
||
await manager.recover(deletedEntity, { data: { action: "restore" } }); | ||
|
||
}))); | ||
|
||
}); |
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,24 @@ | ||
import { expect } from "chai"; | ||
import { EntitySubscriberInterface, EventSubscriber, UpdateEvent } from "../../../../src"; | ||
import { Post } from "../entity/Post"; | ||
|
||
@EventSubscriber() | ||
export class PostSubscriber implements EntitySubscriberInterface<Post> { | ||
listenTo() { | ||
return Post; | ||
} | ||
|
||
afterUpdate(event: UpdateEvent<Post>): void { | ||
const { entity, queryRunner: { data } } = event; | ||
|
||
expect(["soft-delete", "restore"]).to.include(data!.action); | ||
|
||
if (data!.action === "soft-delete") { | ||
expect(Object.prototype.toString.call(entity!.deletedAt)).to.be.eq("[object Date]"); | ||
} | ||
|
||
if (data!.action === "restore") { | ||
expect(entity!.deletedAt).to.be.null; | ||
} | ||
} | ||
} |