"use strict";

var _index = require("../index");

/* eslint-disable max-lines */
test('schema value not containing cli key is replaced by processEnv', () => {
  const schema = {
    firstData: {
      hi: 'hi'
    }
  };
  const customOptions = {};
  const processEnv = {
    hi: 'hello'
  };
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    firstData: {
      hi: 'hi'
    }
  });
}); // NOTE : if schema value type is not an object ,it is not changed by processEnv
// NOTE : if schema is a object but not containing the cli key then also it cannot be changed by processEnv

test('replacing schema value by processEnv', () => {
  const schema = {
    firstData: {
      cli: 'first',
      value: 1
    },
    secondData: {
      cli: 'buddy',
      value: 'hello Buddy'
    }
  };
  const customOptions = {};
  const processEnv = {
    first: 'numberOne',
    buddy: 'hi buddy'
  };
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    firstData: 'numberOne',
    secondData: 'hi buddy'
  });
});
test('assigning value to an object by processEnv', () => {
  const schema = {
    firstData: {
      cli: 'first',
      value: 1
    },
    secondData: {
      cli: 'buddy',
      hello: 'hello Buddy',
      hi: 'hi Buddy'
    }
  };
  const customOptions = {};
  const processEnv = {
    first: 'numberOne',
    buddy: 'helloBuddy'
  };
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    firstData: 'numberOne',
    secondData: 'helloBuddy'
  });
});
test('if process env value  == undefined , it takes schemas value as output', () => {
  const schema = {
    firstData: {
      cli: 'first',
      value: 1
    }
  };
  const customOptions = {};
  const processEnv = {
    first: undefined
  };
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    firstData: 1
  });
});
test('process env value  == null , it takes schemas value as output', () => {
  const schema = {
    firstData: {
      cli: 'first',
      value: 1
    }
  };
  const customOptions = {};
  const processEnv = {
    first: null
  };
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    firstData: 1
  });
});
test('if we change the schema value by customOptions and by processEnv , then process Env value is updated because it has more priority', () => {
  const schema = {
    firstData: {
      cli: 'first',
      value: 1
    }
  };
  const customOptions = {
    firstData: 1
  };
  const processEnv = {
    first: 'one'
  };
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    firstData: 'one'
  });
});
test('object cannot be changed', () => {
  const schema = {
    second: {
      change: 'notdone'
    },
    first: {
      nestedObject1: {
        nestedObject2: {
          nestedObject3: {
            nestedObject4: 'five'
          }
        }
      }
    }
  };
  const customOptions = {
    second: 'done'
  };
  const processEnv = {};
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    second: {
      change: 'notdone'
    },
    first: {
      nestedObject1: {
        nestedObject2: {
          nestedObject3: {
            nestedObject4: 'five'
          }
        }
      }
    }
  });
});
test('replacing nested object it is the proper way', () => {
  const schema = {
    second: {
      change: 'notdone'
    },
    first: {
      nestedObject1: {
        nestedObject2: {
          nestedObject3: {
            nestedObject4: 'five'
          }
        }
      }
    }
  };
  const customOptions = {
    second: {
      change: 'done'
    }
  };
  const processEnv = {};
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    second: {
      change: 'done'
    },
    first: {
      nestedObject1: {
        nestedObject2: {
          nestedObject3: {
            nestedObject4: 'five'
          }
        }
      }
    }
  });
});
test('object cannot be changed (nested Object)', () => {
  const schema = {
    second: {
      change: 'notdone'
    },
    first: {
      nestedObject1: {
        nestedObject2: {
          nestedObject3: {
            nestedObject4: 'five'
          }
        }
      }
    }
  };
  const customOptions = {
    first: {
      nestedObject1: {
        nestedObject2: {
          nestedObject3: {
            nestedObject4: 'changed'
          }
        }
      }
    }
  };
  const processEnv = {};
  const output = (0, _index.applyValuesToSchema)(schema, customOptions, processEnv);
  expect(output).toStrictEqual({
    second: {
      change: 'notdone'
    },
    first: {
      nestedObject1: {
        nestedObject2: {
          nestedObject3: {
            nestedObject4: 'changed'
          }
        }
      }
    }
  });
});