const test = require('tape');
const api = require('../../src/helpers/api');
const fs = require('fs');
const globalModulesPath = require('global-modules');
const { config } = require('dotenv');

test('is API key being correctly set?', (assert) => {
  const testPath = `${globalModulesPath}/tinyme`;
  const testEnvFile = 'variables_test.env';
  const testEnvVarName = 'TINYME_TEST_API_KEY';
  const testApiKey = 'TEST_API_KEY';

  const testEnvApiKey = `${testEnvVarName}="${testApiKey}"`;

  api.save(testApiKey, testPath, testEnvFile, testEnvVarName);
  const settedEnvApiKey = fs.readFileSync(`${testPath}/${testEnvFile}`).toString();

  assert.equal(testEnvApiKey, settedEnvApiKey, 'API has been set correctly');
  assert.end();
});

test('is API key being correctly read?', (assert) => {
  const testPath = `${globalModulesPath}/tinyme`;
  const testEnvFile = 'variables_test.env';
  const testEnvVarName = 'TINYME_TEST_API_KEY';

  config({ path: `${testPath}/${testEnvFile}` });
  const envApiKey = process.env[testEnvVarName];
  const apiKey = api.retrieve(testPath, testEnvFile, testEnvVarName);

  assert.equal(apiKey, envApiKey, 'API key is being correctly returned');
  assert.end();
});

@@ -75,18 +75,32 @@
 ;%0Aconst 
-fs
+%7B readFileSync %7D
  = requi
@@ -590,11 +590,8 @@
 y = 
-fs.
 read

Refactor fs call to use only read file sync