@@ -2,12 +2,14 @@ import { NavFormType } from '@navikt/skjemadigitalisering-shared-domain';
2
2
import nock from 'nock' ;
3
3
import { MockInstance } from 'vitest' ;
4
4
import { Backend } from '../Backend' ;
5
- import config from '../config ' ;
5
+ import { getFormioApiServiceUrl } from '../util/formio ' ;
6
6
import PublisherService from './PublisherService' ;
7
7
import { formioService } from './index' ;
8
8
9
9
const opts = { userName : 'todd' , formioToken : 'valid-formio-token' } ;
10
10
11
+ const FORMIO_API_SERVICE_URL = getFormioApiServiceUrl ( ) ;
12
+
11
13
describe ( 'PublisherService' , ( ) => {
12
14
let publisherService : PublisherService ;
13
15
@@ -26,7 +28,7 @@ describe('PublisherService', () => {
26
28
beforeEach ( ( ) => {
27
29
backendMock = { publishForm : ( ) => 'git-commit-hash' } as unknown as Backend ;
28
30
publisherService = new PublisherService ( formioService , backendMock ) ;
29
- nockScope = nock ( config . formio . projectUrl )
31
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
30
32
. put ( / \/ f o r m \/ ( \d * ) $ / )
31
33
. times ( 1 )
32
34
. reply ( ( uri , requestBody ) => [ 200 , requestBody ] ) ;
@@ -99,7 +101,7 @@ describe('PublisherService', () => {
99
101
} as unknown as Backend ;
100
102
publisherService = new PublisherService ( formioService , backendMock ) ;
101
103
formioServiceSpy = vi . spyOn ( formioService , 'saveForm' ) ;
102
- nockScope = nock ( config . formio . projectUrl )
104
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
103
105
. put ( / \/ f o r m \/ ( \d * ) $ / )
104
106
. times ( 2 )
105
107
. reply ( ( uri , requestBody ) => {
@@ -160,7 +162,7 @@ describe('PublisherService', () => {
160
162
beforeEach ( ( ) => {
161
163
backendMock = { unpublishForm : ( ) => testGitSha } as unknown as Backend ;
162
164
publisherService = new PublisherService ( formioService , backendMock ) ;
163
- nockScope = nock ( config . formio . projectUrl )
165
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
164
166
. put ( / \/ f o r m \/ ( \d * ) $ / )
165
167
. times ( 1 )
166
168
. reply ( ( uri , requestBody ) => [ 200 , requestBody ] ) ;
@@ -197,7 +199,7 @@ describe('PublisherService', () => {
197
199
} ,
198
200
} as unknown as Backend ;
199
201
publisherService = new PublisherService ( formioService , backendMock ) ;
200
- nockScope = nock ( config . formio . projectUrl )
202
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
201
203
. put ( / \/ f o r m \/ ( \d * ) $ / )
202
204
. times ( 2 )
203
205
. reply ( ( uri , requestBody ) => {
@@ -266,7 +268,7 @@ describe('PublisherService', () => {
266
268
formioApiRequestBodies = [ ] ;
267
269
backendMock = { publishForms : ( ) => testGitSha } as unknown as Backend ;
268
270
publisherService = new PublisherService ( formioService , backendMock ) ;
269
- nockScope = nock ( config . formio . projectUrl )
271
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
270
272
. put ( / \/ f o r m \/ ( \d * ) $ / )
271
273
. times ( 3 )
272
274
. reply ( ( uri , requestBody ) => {
@@ -338,7 +340,7 @@ describe('PublisherService', () => {
338
340
} ,
339
341
} as unknown as Backend ;
340
342
publisherService = new PublisherService ( formioService , backendMock ) ;
341
- nockScope = nock ( config . formio . projectUrl )
343
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
342
344
. put ( / \/ f o r m \/ ( \d * ) $ / )
343
345
. times ( 6 ) // 3 before publish, and 3 after publish fails
344
346
. reply ( ( uri , requestBody ) => {
@@ -405,20 +407,20 @@ describe('PublisherService', () => {
405
407
backendMock = { publishForms : ( ) => '123456789' } as unknown as Backend ;
406
408
publisherService = new PublisherService ( formioService , backendMock ) ;
407
409
const formEndpoint = / \/ f o r m \/ ( \d * ) $ / ;
408
- nockScope = nock ( config . formio . projectUrl )
410
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
409
411
. put ( formEndpoint )
410
412
. times ( 2 ) // <-- formio update props succeeds on first two forms
411
413
. reply ( ( uri , requestBody ) => {
412
414
formioApiRequestBodies . push ( requestBody as NavFormType ) ;
413
415
return [ 200 , requestBody ] ;
414
416
} ) ;
415
- nockScope = nock ( config . formio . projectUrl )
417
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
416
418
. put ( formEndpoint )
417
419
. reply ( ( uri , requestBody ) => {
418
420
formioApiRequestBodies . push ( requestBody as NavFormType ) ;
419
421
return [ 500 , 'Internal server error' ] ; // <-- formio update props fails on third form
420
422
} ) ;
421
- nockScope = nock ( config . formio . projectUrl )
423
+ nockScope = nock ( FORMIO_API_SERVICE_URL )
422
424
. put ( formEndpoint )
423
425
. times ( 2 ) // <-- expecting rollback of the two first forms
424
426
. reply ( ( uri , requestBody ) => {
0 commit comments