/
issue-3654.ts
52 lines (44 loc) · 1.68 KB
/
issue-3654.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Connection } from "../../../src";
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases
} from "../../utils/test-utils";
import { User } from "./entity/User";
describe("github issues > #3654 Should be able compare buffer type", () => {
let connections: Connection[];
before(
async () =>
(connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["mysql"]
}))
);
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("Repository.save() method should be able compare buffer type for deciding if save or update ops.", () =>
Promise.all(
connections.map(async connection => {
const userRepo = connection.getRepository(User);
let userId = "4321226123455910A532153E57A78445".toLowerCase();
const user = new User();
user.id = userId;
user.age = 25;
await userRepo.save(user);
const dbUser = (await userRepo.find({
where: {
id: Buffer.from(userId, "hex")
}
}))[0];
dbUser.age = 26;
await userRepo.save(dbUser);
const confirmUser = (await userRepo.find({
where: {
id: Buffer.from(userId, "hex")
}
}))[0];
confirmUser.id.should.be.eql(userId);
confirmUser.age.should.be.eql(26);
})
));
});