@@ -3,13 +3,42 @@ import { Given, When, Then } from '@cucumber/cucumber';
33import type { ICustomWorld } from '../support/custom-world.ts' ;
44import { signUp } from '../support/auth-helper.ts' ;
55
6+ interface PrismaCradle {
7+ prisma : {
8+ user : {
9+ create : ( args : { data : Record < string , unknown > } ) => Promise < { id : string } > ;
10+ findFirst : ( args : {
11+ where : Record < string , unknown > ;
12+ include ?: Record < string , unknown > ;
13+ } ) => Promise < { id : string ; accounts : unknown [ ] } | null > ;
14+ } ;
15+ } ;
16+ }
17+
18+ let legacyIdCounter = 0 ;
19+
620Given (
721 'a registered user with email {string}' ,
822 async function ( this : ICustomWorld , email : string ) {
923 await signUp ( this . server , { email } ) ;
1024 } ,
1125) ;
1226
27+ Given (
28+ 'a legacy user with email {string} and no linked account' ,
29+ async function ( this : ICustomWorld , email : string ) {
30+ const { prisma } = this . server . diContainer . cradle as unknown as PrismaCradle ;
31+ await prisma . user . create ( {
32+ data : {
33+ name : 'Legacy User' ,
34+ email,
35+ emailVerified : true ,
36+ legacyId : ++ legacyIdCounter ,
37+ } ,
38+ } ) ;
39+ } ,
40+ ) ;
41+
1342Given (
1443 'a verified user with email {string} and password {string}' ,
1544 async function ( this : ICustomWorld , email : string , password : string ) {
6493 assert . ok ( code >= 400 , `Expected error status code, got ${ code } ` ) ;
6594 } ,
6695) ;
96+
97+ async function findAccountCount ( this : ICustomWorld , email : string ) : Promise < number > {
98+ const { prisma } = this . server . diContainer . cradle as unknown as PrismaCradle ;
99+ const user = await prisma . user . findFirst ( { where : { email } , include : { accounts : true } } ) ;
100+ assert . ok ( user , `Expected a user with email "${ email } "` ) ;
101+ return user . accounts . length ;
102+ }
103+
104+ Then (
105+ 'the user {string} should still have no linked account' ,
106+ async function ( this : ICustomWorld , email : string ) {
107+ const count = await findAccountCount . call ( this , email ) ;
108+ assert . strictEqual ( count , 0 , `Expected no linked account, found ${ count } ` ) ;
109+ } ,
110+ ) ;
111+
112+ Then (
113+ 'the user {string} should have a linked account' ,
114+ async function ( this : ICustomWorld , email : string ) {
115+ const count = await findAccountCount . call ( this , email ) ;
116+ assert . ok ( count > 0 , 'Expected a linked account, found none' ) ;
117+ } ,
118+ ) ;
0 commit comments