flagsmith-nodejs
Version:
Flagsmith lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.
33 lines (22 loc) • 1.13 kB
text/typescript
import * as fs from 'fs';
import { LocalFileHandler } from '../../sdk/offline_handlers.js';
import { EnvironmentModel } from '../../flagsmith-engine/index.js';
import * as offlineEnvironment from './data/offline-environment.json';
vi.mock('fs');
const offlineEnvironmentString = JSON.stringify(offlineEnvironment);
test('local file handler', () => {
const environmentDocumentFilePath = '/some/path/environment.json';
// Mock the fs.readFileSync function to return environmentJson
const readFileSyncMock = vi.spyOn(fs, 'readFileSync');
readFileSyncMock.mockImplementation(() => offlineEnvironmentString);
// Given
const localFileHandler = new LocalFileHandler(environmentDocumentFilePath);
// When
const environmentModel = localFileHandler.getEnvironment();
// Then
expect(environmentModel).toBeInstanceOf(EnvironmentModel);
expect(environmentModel.apiKey).toBe('B62qaMZNwfiqT76p38ggrQ');
expect(readFileSyncMock).toHaveBeenCalledWith(environmentDocumentFilePath, 'utf8');
// Restore the original implementation of fs.readFileSync
readFileSyncMock.mockRestore();
});