refactor: Only delete old test users once at preload

This commit is contained in:
Jesse Wierzbinski 2024-05-28 14:51:55 -10:00
parent f5a0f52b93
commit 5b658984a5
No known key found for this signature in database
30 changed files with 38 additions and 200 deletions

View file

@ -1,2 +1,5 @@
[install.scopes]
"@jsr" = "https://npm.jsr.io"
[test]
preload = ["./tests/setup.ts"]

View file

@ -1,6 +1,6 @@
import { drizzle } from "drizzle-orm/node-postgres";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import { LogLevel, type LogManager, type MultiLogManager } from "log-manager";
import { LogLevel, LogManager, type MultiLogManager } from "log-manager";
import { Client } from "pg";
import { config } from "~/packages/config-manager";
import * as schema from "./schema";
@ -14,7 +14,7 @@ export const client = new Client({
});
export const setupDatabase = async (
logger: LogManager | MultiLogManager,
logger: LogManager | MultiLogManager = new LogManager(Bun.stdout),
info = true,
) => {
try {

View file

@ -4,15 +4,9 @@ import { eq } from "drizzle-orm";
import { db } from "~drizzle/db";
import { Applications } from "~drizzle/schema";
import { config } from "~packages/config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, deleteUsers, passwords } = await getTestUsers(1);
// Create application

View file

@ -4,15 +4,9 @@ import { eq } from "drizzle-orm";
import { db } from "~drizzle/db";
import { Applications } from "~drizzle/schema";
import { config } from "~packages/config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, deleteUsers, passwords } = await getTestUsers(1);
const token = randomBytes(32).toString("hex");
const newPassword = randomBytes(16).toString("hex");

View file

@ -1,15 +1,9 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Relationship as APIRelationship } from "~types/mastodon/relationship";
import { meta } from "./block";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(2);
afterAll(async () => {

View file

@ -1,15 +1,9 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Relationship as APIRelationship } from "~types/mastodon/relationship";
import { meta } from "./follow";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(2);
afterAll(async () => {

View file

@ -1,15 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./followers";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
afterAll(async () => {

View file

@ -1,15 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./following";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
afterAll(async () => {

View file

@ -1,16 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
const timeline = (await getTestStatuses(40, users[0])).toReversed();

View file

@ -1,15 +1,9 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Relationship as APIRelationship } from "~types/mastodon/relationship";
import { meta } from "./mute";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(2);
afterAll(async () => {

View file

@ -1,16 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Status as APIStatus } from "~types/mastodon/status";
import { meta } from "./statuses";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
const timeline = (await getTestStatuses(40, users[1])).toReversed();
const timeline2 = (await getTestStatuses(40, users[2])).toReversed();

View file

@ -1,15 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Relationship as APIRelationship } from "~types/mastodon/relationship";
import { meta } from "./unmute";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(2);
afterAll(async () => {

View file

@ -11,12 +11,7 @@ import { config } from "config-manager";
import { eq } from "drizzle-orm";
import { db } from "~drizzle/db";
import { Users } from "~drizzle/schema";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./index";

View file

@ -1,15 +1,9 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
afterAll(async () => {

View file

@ -1,15 +1,9 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
afterAll(async () => {

View file

@ -1,15 +1,8 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(1);
const timeline = await getTestStatuses(10, users[0]);

View file

@ -1,14 +1,8 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(3);
afterAll(async () => {

View file

@ -1,15 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Notification as APINotification } from "~types/mastodon/notification";
import { meta } from "./dismiss";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(2);
let notifications: APINotification[] = [];

View file

@ -1,15 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Notification as APINotification } from "~types/mastodon/notification";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(2);
let notifications: APINotification[] = [];

View file

@ -1,15 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Notification as APINotification } from "~types/mastodon/notification";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(2);
let notifications: APINotification[] = [];

View file

@ -1,16 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Notification as APINotification } from "~types/mastodon/notification";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(2);
const statuses = await getTestStatuses(40, users[0]);
let notifications: APINotification[] = [];

View file

@ -1,16 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Notification as APINotification } from "~types/mastodon/notification";
import { meta } from "./index";
await deleteOldTestUsers();
const getFormData = (object: Record<string, string | number | boolean>) =>
Object.keys(object).reduce((formData, key) => {
formData.append(key, String(object[key]));

View file

@ -1,14 +1,8 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "~packages/config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import { meta } from "./index";
await deleteOldTestUsers();
const { deleteUsers, tokens } = await getTestUsers(1);
afterAll(async () => {

View file

@ -1,14 +1,8 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "~packages/config-manager";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import { meta } from "./index";
await deleteOldTestUsers();
const { deleteUsers, tokens } = await getTestUsers(1);
afterAll(async () => {

View file

@ -1,16 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./favourited_by";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
const timeline = (await getTestStatuses(40, users[0])).toReversed();

View file

@ -1,16 +1,9 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import { meta } from "./reblogged_by";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
const timeline = (await getTestStatuses(40, users[0])).toReversed();

View file

@ -3,16 +3,10 @@ import { config } from "config-manager";
import { eq } from "drizzle-orm";
import { db } from "~drizzle/db";
import { Emojis } from "~drizzle/schema";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestUsers, sendTestRequest } from "~tests/utils";
import type { Status as APIStatus } from "~types/mastodon/status";
import { meta } from "./index";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
afterAll(async () => {

View file

@ -1,16 +1,9 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Status as APIStatus } from "~types/mastodon/status";
import { meta } from "./home";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
const timeline = (await getTestStatuses(40, users[0])).toReversed();

View file

@ -1,16 +1,9 @@
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import {
deleteOldTestUsers,
getTestStatuses,
getTestUsers,
sendTestRequest,
} from "~tests/utils";
import { getTestStatuses, getTestUsers, sendTestRequest } from "~tests/utils";
import type { Status as APIStatus } from "~types/mastodon/status";
import { meta } from "./public";
await deleteOldTestUsers();
const { users, tokens, deleteUsers } = await getTestUsers(5);
const timeline = (await getTestStatuses(40, users[0])).toReversed();

5
tests/setup.ts Normal file
View file

@ -0,0 +1,5 @@
import { setupDatabase } from "~drizzle/db";
import { deleteOldTestUsers } from "./utils";
await setupDatabase();
await deleteOldTestUsers();