import { readProjectConfiguration } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import * as utils from '@abgov/nx-oc'; import { environments } from '@abgov/nx-oc'; import { Schema } from './schema'; import generator from './pern'; jest.mock('@nx/devkit', () => ({ ...jest.requireActual('@nx/devkit'), formatFiles: jest.fn().mockResolvedValue(undefined), })); jest.mock('@abgov/nx-oc'); jest.mock('../../utils/agent', () => ({ consultAgent: jest.fn().mockResolvedValue(null), confirmAfterAgentInterrupt: jest.fn().mockResolvedValue(undefined), })); const utilsMock = utils as jest.Mocked; utilsMock.getAdspConfiguration.mockResolvedValue({ tenant: 'test', tenantRealm: 'test', accessServiceUrl: environments.test.accessServiceUrl, directoryServiceUrl: environments.test.directoryServiceUrl, }); // jest.mock('@abgov/nx-oc') automocks adspProjectTags too — restore the real // (pure, no I/O) implementation so tag-writing behavior is actually exercised. utilsMock.adspProjectTags.mockImplementation( jest.requireActual('@abgov/nx-oc').adspProjectTags, ); utilsMock.ensureAdspToken.mockResolvedValue('test-token'); describe('PERN Generator', () => { const options: Schema = { name: 'test', env: 'dev', }; it('can run', async () => { const host = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generator(host, options); const appConfig = readProjectConfiguration(host, 'test-app'); expect(appConfig.root).toBe('apps/test-app'); const serviceConfig = readProjectConfiguration(host, 'test-service'); expect(serviceConfig.root).toBe('apps/test-service'); expect(host.exists('apps/test-app/nginx.conf')).toBeTruthy(); const nginxConf = host.read('apps/test-app/nginx.conf').toString(); expect(nginxConf).toContain('http://test-service:3333/'); expect(host.exists('apps/test-service/src/db/schema.ts')).toBeTruthy(); }, 30000); });