mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
Fix user createdAt being updatedAt instead
This commit is contained in:
parent
cd9a98de7c
commit
02e5d8fb46
|
|
@ -722,11 +722,10 @@ export function upsert(
|
|||
) {
|
||||
return db
|
||||
.insertInto("User")
|
||||
.values(args)
|
||||
.values({ ...args, createdAt: databaseTimestampNow() })
|
||||
.onConflict((oc) => {
|
||||
return oc.column("discordId").doUpdateSet({
|
||||
...R.omit(args, ["discordId"]),
|
||||
createdAt: databaseTimestampNow(),
|
||||
});
|
||||
})
|
||||
.returning("id")
|
||||
|
|
|
|||
63
app/features/user-page/UserRepository.test.ts
Normal file
63
app/features/user-page/UserRepository.test.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { afterEach, describe, expect, test } from "vitest";
|
||||
import { dbReset } from "~/utils/Test";
|
||||
import * as UserRepository from "./UserRepository.server";
|
||||
|
||||
describe("UserRepository", () => {
|
||||
afterEach(() => {
|
||||
dbReset();
|
||||
});
|
||||
|
||||
test("created user has createdAt field", async () => {
|
||||
await UserRepository.upsert({
|
||||
discordId: "1",
|
||||
discordName: "TestUser",
|
||||
discordAvatar: null,
|
||||
});
|
||||
|
||||
const user = await UserRepository.findModInfoById(1);
|
||||
|
||||
expect(user).toBeDefined();
|
||||
expect(user?.createdAt).toBeDefined();
|
||||
});
|
||||
|
||||
test("updates user name when upserting", async () => {
|
||||
await UserRepository.upsert({
|
||||
discordId: "1",
|
||||
discordName: "TestUser",
|
||||
discordAvatar: null,
|
||||
});
|
||||
|
||||
const user = await UserRepository.findLayoutDataByIdentifier("1");
|
||||
|
||||
expect(user?.username).toBe("TestUser");
|
||||
|
||||
await UserRepository.upsert({
|
||||
discordId: "1",
|
||||
discordName: "UpdatedUser",
|
||||
discordAvatar: null,
|
||||
});
|
||||
|
||||
const updatedUser = await UserRepository.findLayoutDataByIdentifier("1");
|
||||
expect(updatedUser?.username).toBe("UpdatedUser");
|
||||
});
|
||||
|
||||
test("updating a user doesn't change the createdAt field", async () => {
|
||||
await UserRepository.upsert({
|
||||
discordId: "1",
|
||||
discordName: "TestUser",
|
||||
discordAvatar: null,
|
||||
});
|
||||
|
||||
const user = await UserRepository.findModInfoById(1);
|
||||
const createdAt = user?.createdAt;
|
||||
|
||||
await UserRepository.upsert({
|
||||
discordId: "1",
|
||||
discordName: "UpdatedUser",
|
||||
discordAvatar: null,
|
||||
});
|
||||
|
||||
const updatedUser = await UserRepository.findModInfoById(1);
|
||||
expect(updatedUser?.createdAt).toEqual(createdAt);
|
||||
});
|
||||
});
|
||||
6
migrations/092-user-created-at-null.js
Normal file
6
migrations/092-user-created-at-null.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export function up(db) {
|
||||
db.transaction(() => {
|
||||
// there was a bug in the past where createdAt was set when account was updated instead
|
||||
db.prepare(/* sql */ `update "User" set "createdAt" = null`).run();
|
||||
})();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user