{"size": 1968, "ext": "js", "max_stars_repo_path": "test/document.js", "max_stars_repo_name": "benhutchins/imponderous", "max_stars_repo_stars_event_min_datetime": "2015-09-24T05:22:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-26T13:11:22.000Z", "max_issues_repo_path": "test/document.js", "max_issues_repo_name": "benhutchins/imponderous", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/document.js", "max_forks_repo_name": "benhutchins/imponderous", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.5584415584, "max_line_length": 66, "alphanum_fraction": 0.5980691057}
'use strict'

let assert = require('assert-plus')

describe('Document', function () {
  let imponderous = require('../index')
  let user = require('./docs/user')

  imponderous.connect(__dirname + '/db')

  describe('.key', () => {
    it('should return a valid UUID', () => {
      assert.string(user.key)
      assert.uuid(user.key)
    })

    it('should allow key reassignment', () => {
      let oldKey = user.key
      user.key = 'tuser'
      assert.equal(user.key, 'tuser')
      assert.equal(user._oldKey, oldKey)
    })
  })

  describe('#get', function () {
    it('should provide undefined to unknown fields', function () {
      assert.equal(user.get('undefined'), undefined)
    })

    it('should return values for known fields', function () {
      // using .get() method
      assert.bool(user.get('spam'))
      assert.equal(user.get('spam'), false)

      // using .field method
      assert.bool(user.spam)
      assert.equal(user.spam, false)
    })

    it('should traverse dotted notation for fields', function () {
      assert.string(user.get('name.first'))
      assert.equal(user.get('name.first'), 'John')
    })
  })

  describe('#set', function () {
    it('should set value for new fields', function () {
      user.set('email', 'test@example.com')

      assert.string(user.data.email)
      assert.equal(user.data.email, 'test@example.com')
    })

    it('should traverse dotted notation for field', function () {
      user.set('name.last', 'Smith')

      assert.string(user.data.name.last)
      assert.equal(user.data.name.last, 'Smith')
    })
  })

  describe('#rm', function () {
    it('should delete single property', function () {
      user.rm('email')

      assert.equal(user.get('email'), undefined)
    })

    it('should delete multiple properties', function () {
      user.rm('name.first', 'spam')

      assert.equal(user.get('name.first'), undefined)
      assert.equal(user.get('spam'), undefined)
    })
  })
})
