@mbc-cqrs-serverless/cli
Version:
a CLI to get started with MBC CQRS serverless framework
36 lines (35 loc) • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const new_action_1 = require("./new.action");
const { updateEnvLocal } = new_action_1.exportsForTesting;
jest.mock('fs');
describe('updateEnvLocal', () => {
const mockEnvContent = `
# name of application
APP_NAME=%%projectName%%
# name of docker compose
COMPOSE_PROJECT_NAME=%%projectName%%
`;
const envPath = './.env.local';
beforeEach(() => {
jest.clearAllMocks();
});
it('should update the specified value in the .env.local file', () => {
const searchValue = '%%projectName%%';
const replaceValue = 'new-project-name';
fs_1.readFileSync.mockReturnValue(mockEnvContent);
updateEnvLocal(envPath, searchValue, replaceValue);
expect(fs_1.readFileSync).toHaveBeenCalledWith(envPath, 'utf8');
const expectedContent = mockEnvContent.replaceAll(searchValue, replaceValue);
expect(fs_1.writeFileSync).toHaveBeenCalledWith(envPath, expectedContent);
});
it('should not change the file content if searchValue is not found', () => {
const searchValue = 'non-existent-value';
const replaceValue = 'new-project-name';
fs_1.readFileSync.mockReturnValue(mockEnvContent);
updateEnvLocal(envPath, searchValue, replaceValue);
expect(fs_1.readFileSync).toHaveBeenCalledWith(envPath, 'utf8');
expect(fs_1.writeFileSync).toHaveBeenCalledWith(envPath, mockEnvContent);
});
});