/**
 * Test Dependencies
 */

import './helper.js'
import chai from 'chai'
const expect = chai.expect
import sinonChai from 'sinon-chai'
chai.use(sinonChai)

import { defaults } from '../src/schema.js'

describe('Schema', () => {
  describe('#defaults', () => {
    describe('string', () => {
      it('const', () => {
        const schema = {
          type: 'string',
          const: 'Hello, Const!'
        }

        const result = defaults(schema)

        expect(result).to.eql('Hello, Const!')
      })

      it('default', () => {
        const schema = {
          type: 'string',
          default: 'Hello, Default!'
        }

        const result = defaults(schema)

        expect(result).to.eql('Hello, Default!')
      })

      it('const and default', () => {
        const schema = {
          type: 'string',
          const: 'Hello, Const!',
          default: 'Hello, Default!'
        }

        const result = defaults(schema)

        expect(result).to.eql('Hello, Const!')
      })
    })

    describe('object', () => {
      it('Control Envy component with source', () => {
        const schema = {
          type: 'object',
          properties: {
            name: {
              type: 'string',
              default: 'Component'
            },
            sources: {
              type: 'object',
              properties: {
                '1': {
                  type: 'object',
                  properties: {
                    name: {
                      type: 'string',
                      default: 'Source 1'
                    }
                  }
                }
              }
            }
          }
        }

        const result = defaults(schema)

        expect(result).to.be.eql({
          name: 'Component',
          sources: {
            '1': {
              name: 'Source 1'
            }
          }
        })
      })
    })
  })
})