From 2096e23e3584a319b4a3e184747f2823a4d17a97 Mon Sep 17 00:00:00 2001
From: David Mehren <git@herrmehren.de>
Date: Tue, 7 Dec 2021 16:39:46 +0100
Subject: [PATCH] test: allow creating testSetup with users

Signed-off-by: David Mehren <git@herrmehren.de>
---
 test/test-setup.ts | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/test/test-setup.ts b/test/test-setup.ts
index 28b08edc9..9e235ac5e 100644
--- a/test/test-setup.ts
+++ b/test/test-setup.ts
@@ -36,6 +36,7 @@ import { NotesModule } from '../src/notes/notes.module';
 import { NotesService } from '../src/notes/notes.service';
 import { PermissionsModule } from '../src/permissions/permissions.module';
 import { RevisionsModule } from '../src/revisions/revisions.module';
+import { User } from '../src/users/user.entity';
 import { UsersModule } from '../src/users/users.module';
 import { UsersService } from '../src/users/users.service';
 import { setupSessionMiddleware } from '../src/utils/session';
@@ -52,6 +53,8 @@ export class TestSetup {
   historyService: HistoryService;
   aliasService: AliasService;
 
+  users: User[] = [];
+
   public static async create(): Promise<TestSetup> {
     const testSetup = new TestSetup();
     const routes: Routes = [
@@ -129,4 +132,24 @@ export class TestSetup {
 
     return testSetup;
   }
+
+  public async withUsers(): Promise<TestSetup> {
+    // Create users
+    this.users.push(
+      await this.userService.createUser('testuser1', 'Test User 1'),
+    );
+    this.users.push(
+      await this.userService.createUser('testuser2', 'Test User 2'),
+    );
+    this.users.push(
+      await this.userService.createUser('testuser3', 'Test User 3'),
+    );
+
+    // Create identities for login
+    await this.identityService.createLocalIdentity(this.users[0], 'testuser1');
+    await this.identityService.createLocalIdentity(this.users[1], 'testuser2');
+    await this.identityService.createLocalIdentity(this.users[2], 'testuser3');
+
+    return this;
+  }
 }