{"size": 1603, "ext": "js", "max_stars_repo_path": "test/Lens.test.js", "max_stars_repo_name": "OrgVue/data-control", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/Lens.test.js", "max_issues_repo_name": "OrgVue/data-control", "max_issues_repo_issues_event_min_datetime": "2020-04-21T08:58:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-21T08:58:12.000Z", "max_forks_repo_path": "test/Lens.test.js", "max_forks_repo_name": "OrgVue/data-control", "max_forks_repo_forks_event_min_datetime": "2018-11-30T09:51:29.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-04T10:41:18.000Z"}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": 2, "avg_line_length": 23.5735294118, "max_line_length": 76, "alphanum_fraction": 0.5109170306}
"use strict"

const assert = require('assert')
// const doc = require('crocodile').doc 
const doc = x => x()
const Lens = require('../src/Lens.js')

const compose = g => f => x => g(f(x))

const obj = {
  name: "Piet",
  address: {
    street: "5th Avenue",
    zip: "bh 90210"
  }
}

var lens = compose(Lens.ofProp("address"))(Lens.ofProp("street"))

doc(function() {
  describe("Lens", function() {
    describe("#Id", function() {
      it("should be the top level lens", function() {
        const obj = {
          name: "Andy Z."
        }

        assert.deepStrictEqual(Lens.view(Lens.Id)(obj), { name: "Andy Z." })
        assert.deepStrictEqual(Lens.over(Lens.Id)(x => {
          x.name = "Andy"

          return x
        })(obj), { name: "Andy" })
      })
    })

    describe("#over", function() {
      it("should reach inside an object and update", function() {
        assert.deepStrictEqual(Lens.over(lens)(x => x.toUpperCase())(obj), {
          name: "Piet",
          address: {
            street: "5TH AVENUE",
            zip: "bh 90210"
          }
        })
      })
    })

    describe("#set", function() {
      it("should set a value inside an object", function() {
        assert.deepStrictEqual(Lens.set(lens)("Unknown Street")(obj), {
          name: "Piet",
          address: {
            street: "Unknown Street",
            zip: "bh 90210"
          }
        })
      })
    })

    describe("#view", function() {
      it("should read from inside an object", function() {
        assert.strictEqual("5th Avenue", Lens.view(lens)(obj))
      })
    })
  })
})
