@@ -4,7 +4,11 @@ import slug from "slug";
44import { describe , expect , vi } from "vitest" ;
55import { ArchiveBranchService } from "~/services/archiveBranch.server" ;
66import { UpsertBranchService } from "~/services/upsertBranch.server" ;
7- import { createTestOrgProjectWithMember , uniqueId } from "./fixtures/environmentVariablesFixtures" ;
7+ import {
8+ createTestOrgProjectWithMember ,
9+ createTestUser ,
10+ uniqueId ,
11+ } from "./fixtures/environmentVariablesFixtures" ;
812
913vi . setConfig ( { testTimeout : 60_000 } ) ;
1014
@@ -77,6 +81,61 @@ describe("UpsertBranchService — DEVELOPMENT parent", () => {
7781 }
7882 ) ;
7983
84+ postgresTest ( "allows different members to use the same branch name" , async ( { prisma } ) => {
85+ const {
86+ organization,
87+ project,
88+ user : firstUser ,
89+ orgMember : firstMember ,
90+ } = await createTestOrgProjectWithMember ( prisma ) ;
91+ const secondUser = await createTestUser ( prisma ) ;
92+ const secondMember = await prisma . orgMember . create ( {
93+ data : {
94+ organizationId : organization . id ,
95+ userId : secondUser . id ,
96+ role : "MEMBER" ,
97+ } ,
98+ } ) ;
99+
100+ await Promise . all ( [
101+ createDevRoot ( prisma , project . id , organization . id , firstMember . id ) ,
102+ createDevRoot ( prisma , project . id , organization . id , secondMember . id ) ,
103+ ] ) ;
104+
105+ const options = {
106+ projectId : project . id ,
107+ env : "development" as const ,
108+ branchName : "shared-name" ,
109+ } ;
110+ const [ firstResult , secondResult ] = await Promise . all ( [
111+ new UpsertBranchService ( prisma ) . call (
112+ { type : "userMembership" , userId : firstUser . id } ,
113+ options
114+ ) ,
115+ new UpsertBranchService ( prisma ) . call (
116+ { type : "userMembership" , userId : secondUser . id } ,
117+ options
118+ ) ,
119+ ] ) ;
120+
121+ expect ( firstResult . success && secondResult . success ) . toBe ( true ) ;
122+ if ( ! firstResult . success || ! secondResult . success ) return ;
123+ expect ( firstResult . branch . id ) . not . toBe ( secondResult . branch . id ) ;
124+ expect ( firstResult . branch . slug ) . toBe ( secondResult . branch . slug ) ;
125+ expect ( firstResult . branch . shortcode ) . not . toBe ( secondResult . branch . shortcode ) ;
126+ expect ( firstResult . branch . orgMemberId ) . toBe ( firstMember . id ) ;
127+ expect ( secondResult . branch . orgMemberId ) . toBe ( secondMember . id ) ;
128+
129+ const firstRetry = await new UpsertBranchService ( prisma ) . call (
130+ { type : "userMembership" , userId : firstUser . id } ,
131+ options
132+ ) ;
133+ expect ( firstRetry . success ) . toBe ( true ) ;
134+ if ( ! firstRetry . success ) return ;
135+ expect ( firstRetry . alreadyExisted ) . toBe ( true ) ;
136+ expect ( firstRetry . branch . id ) . toBe ( firstResult . branch . id ) ;
137+ } ) ;
138+
80139 postgresTest (
81140 "rejects an invalid branch name without touching the database" ,
82141 async ( { prisma } ) => {
0 commit comments