/*
 * Copyright (c) 2020 Pangeanic SL.
 *
 * This file is part of NEC TM
 * (see https://github.com/shasha79/nectm).
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
const assume = require('assume');
const env = require('./');

describe('env-variable', function () {
  it('merges with process.env as we are running on node', function () {
    process.env.TESTING_ENVS = 'wat';

    const data = env();
    assume(data.TESTING_ENVS).equals('wat');
    assume(data.foo).is.a('undefined');

    const merged = env({ foo: 'bar' });

    assume(merged.TESTING_ENVS).equals('wat');
    assume(merged.foo).equals('bar');
  });

  it('lowercases keys', function () {
    process.env.UPPERCASE = 'does NOT touch VALUES';

    const data = env({ FOO: 'bar' });

    assume(data.UPPERCASE).equals('does NOT touch VALUES');
    assume(data.uppercase).equals('does NOT touch VALUES');
    assume(data.FOO).equals('bar');
    assume(data.foo).equals('bar');
  });

  describe('#merge', function () {
    it('merges objects', function () {
      const data = {};

      env.merge(data, { foo: 'bar' });
      assume(data).deep.equals({ foo: 'bar' });
    });
  });

  describe('#parse', function () {
    it('parses basic query strings', function () {
      const data = env.parse('foo=bar');

      assume(data).is.a('object');
      assume(data).deep.equals({ foo: 'bar' });
    });
  });
});
