@@ -145,6 +145,64 @@ describe('SOAService', () => {
145145 } ) ;
146146 } ) ;
147147
148+ describe ( 'getSetup' , ( ) => {
149+ const dto = { frameworkId : 'fw-1' , organizationId : 'org-1' } ;
150+
151+ it ( 'throws NotFoundException when framework not found' , async ( ) => {
152+ mockDb . frameworkEditorFramework . findUnique . mockResolvedValue ( null ) ;
153+ await expect ( service . getSetup ( dto ) ) . rejects . toThrow ( NotFoundException ) ;
154+ } ) ;
155+
156+ it ( 'returns success:false for non-ISO 27001 framework' , async ( ) => {
157+ (
158+ mockDb . frameworkEditorFramework . findUnique as jest . Mock
159+ ) . mockResolvedValue ( { id : 'fw-1' , name : 'SOC 2' } ) ;
160+ const result = await service . getSetup ( dto ) ;
161+ expect ( result . success ) . toBe ( false ) ;
162+ expect ( result . error ) . toContain ( 'ISO 27001' ) ;
163+ } ) ;
164+
165+ it ( 'returns nulls without creating when configuration and document are missing' , async ( ) => {
166+ (
167+ mockDb . frameworkEditorFramework . findUnique as jest . Mock
168+ ) . mockResolvedValue ( { id : 'fw-1' , name : 'ISO 27001' } ) ;
169+ (
170+ mockDb . sOAFrameworkConfiguration . findFirst as jest . Mock
171+ ) . mockResolvedValue ( null ) ;
172+ ( mockDb . sOADocument . findFirst as jest . Mock ) . mockResolvedValue ( null ) ;
173+
174+ const result = await service . getSetup ( dto ) ;
175+
176+ expect ( result . success ) . toBe ( true ) ;
177+ expect ( result . configuration ) . toBeNull ( ) ;
178+ expect ( result . document ) . toBeNull ( ) ;
179+ expect ( mockDb . sOAFrameworkConfiguration . create ) . not . toHaveBeenCalled ( ) ;
180+ expect ( mockDb . sOADocument . create ) . not . toHaveBeenCalled ( ) ;
181+ } ) ;
182+
183+ it ( 'returns existing configuration and document without mutating' , async ( ) => {
184+ const config = { id : 'cfg-1' , questions : [ { id : 'q1' } ] } ;
185+ const doc = { id : 'doc-1' , answers : [ ] } ;
186+ (
187+ mockDb . frameworkEditorFramework . findUnique as jest . Mock
188+ ) . mockResolvedValue ( { id : 'fw-1' , name : 'ISO 27001' } ) ;
189+ (
190+ mockDb . sOAFrameworkConfiguration . findFirst as jest . Mock
191+ ) . mockResolvedValue ( config ) ;
192+ ( mockDb . sOADocument . findFirst as jest . Mock ) . mockResolvedValue ( doc ) ;
193+
194+ const result = await service . getSetup ( dto ) ;
195+
196+ expect ( result ) . toEqual ( {
197+ success : true ,
198+ configuration : config ,
199+ document : doc ,
200+ } ) ;
201+ expect ( mockDb . sOAFrameworkConfiguration . create ) . not . toHaveBeenCalled ( ) ;
202+ expect ( mockDb . sOADocument . create ) . not . toHaveBeenCalled ( ) ;
203+ } ) ;
204+ } ) ;
205+
148206 describe ( 'approveDocument' , ( ) => {
149207 const dto = { documentId : 'doc-1' , organizationId : 'org-1' } ;
150208 const userId = 'user-1' ;
0 commit comments