Merge branch '16602-wb2-acr-version' refs #16602
[arvados-workbench2.git] / src / models / test-utils.ts
index 4d75b1064a00505ba0b8aa2cf949e37dde6ad8ff..1e1041a1d37f5ec9bc990efd87d98870dd1bc609 100644 (file)
@@ -2,21 +2,11 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { GroupResource } from "./group";
+import { GroupClass, GroupResource } from "./group";
 import { Resource, ResourceKind } from "./resource";
+import { ProjectResource } from "./project";
 
-type ResourceUnion = GroupResource;
-
-export const mockResource = (kind: ResourceKind, data: Partial<Exclude<ResourceUnion, "kind">>) => {
-    switch (kind) {
-        case ResourceKind.Group:
-            return mockGroupResource({ ...data, kind });
-        default:
-            return mockCommonResource({ ...data, kind });
-    }
-};
-
-export const mockGroupResource = (data: Partial<Exclude<GroupResource, "kind">>): GroupResource => ({
+export const mockGroupResource = (data: Partial<GroupResource> = {}): GroupResource => ({
     createdAt: "",
     deleteAt: "",
     description: "",
@@ -24,7 +14,7 @@ export const mockGroupResource = (data: Partial<Exclude<GroupResource, "kind">>)
     groupClass: null,
     href: "",
     isTrashed: false,
-    kind: ResourceKind.Group,
+    kind: ResourceKind.GROUP,
     modifiedAt: "",
     modifiedByClientUuid: "",
     modifiedByUserUuid: "",
@@ -33,17 +23,23 @@ export const mockGroupResource = (data: Partial<Exclude<GroupResource, "kind">>)
     properties: "",
     trashAt: "",
     uuid: "",
-    writeableBy: []
+    writableBy: [],
+    ensure_unique_name: true,
+    ...data
 });
 
-const mockCommonResource = <T extends Resource>(data: Partial<T> & { kind: ResourceKind }): Resource => ({
+export const mockProjectResource = (data: Partial<ProjectResource> = {}): ProjectResource =>
+    mockGroupResource({ ...data, groupClass: GroupClass.PROJECT }) as ProjectResource;
+
+export const mockCommonResource = (data: Partial<Resource>): Resource => ({
     createdAt: "",
     etag: "",
     href: "",
-    kind: data.kind,
+    kind: ResourceKind.NONE,
     modifiedAt: "",
     modifiedByClientUuid: "",
     modifiedByUserUuid: "",
     ownerUuid: "",
-    uuid: ""
+    uuid: "",
+    ...data
 });