Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: updating with only
update: false
columns shouldn't trigger @Up…
…dateDateColumn column updation * test: add test case for 8394 WIP * test(8393): add entity for test case WIP * test(8393): remove unrelated text * test(8393): fix compilation errors * test(8393): use chai syntax * test(8393); remove unnecessary logs and update test name * test(8393): remove unnecessary logs and update test name * fix(update): disallowing to pass empty object / only readonly props to update Closes #8394 * fix(update): disallowing to pass object with only readonly props to update Closes #8394 * refactor(update): correct code review requested changed Closes #8394 * ci: trigger build
- Loading branch information
Showing
3 changed files
with
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
Column, | ||
Entity, | ||
UpdateDateColumn, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src"; | ||
|
||
@Entity() | ||
export class Post { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
// Extra, not required column just for the example | ||
@Column() | ||
title: string; | ||
|
||
@UpdateDateColumn() | ||
lastUpdated: Date; | ||
|
||
@Column({ | ||
// Forcing this column to only be written on insert time | ||
update: false | ||
}) | ||
readOnlyColumn: number; | ||
} |
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,55 @@ | ||
import "reflect-metadata"; | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
reloadTestingDatabases | ||
} from "../../utils/test-utils"; | ||
import { Connection, UpdateValuesMissingError } from "../../../src/"; | ||
import { expect } from "chai"; | ||
import { Post } from "./entity/Post"; | ||
|
||
describe("github issues > #8393 When trying to update `update: false` column with `@UpdateDateColumn` the update column is updated", () => { | ||
let connections: Connection[]; | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})) | ||
); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should not update the @UpdateDateColumn column when trying to update un-updatable column", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
const post = new Post(); | ||
post.title = "Control flow based type analysis"; | ||
post.readOnlyColumn = 1; | ||
|
||
await connection.manager.save(post); | ||
|
||
const updateResultPromise = connection.manager.update(Post, post.id, { | ||
// Make a change to read only column | ||
readOnlyColumn: 2, | ||
}); | ||
|
||
await expect(updateResultPromise).to.be.rejectedWith(UpdateValuesMissingError); | ||
|
||
const updatedPost = await connection.manager.findOne( | ||
Post, | ||
post.id | ||
); | ||
|
||
expect(updatedPost).to.be.an("object"); | ||
|
||
expect(post.readOnlyColumn).to.be.equal( | ||
updatedPost!.readOnlyColumn | ||
); | ||
|
||
// Gonna be false | ||
expect(post.lastUpdated.toString()).to.be.eql(updatedPost!.lastUpdated.toString()); | ||
}) | ||
)); | ||
}); |