{"size": 1466, "ext": "js", "max_stars_repo_path": "test/spec/ResourceSpec.js", "max_stars_repo_name": "janstuemmel/fhir-proof", "max_stars_repo_stars_event_min_datetime": "2017-06-20T07:05:32.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-18T01:20:37.000Z", "max_issues_repo_path": "test/spec/ResourceSpec.js", "max_issues_repo_name": "janstuemmel/fhir-proof", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/spec/ResourceSpec.js", "max_forks_repo_name": "janstuemmel/fhir-proof", "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": 14.3725490196, "max_line_length": 64, "alphanum_fraction": 0.4815825375}
import t from 'tcomb';

import Resource from '../../lib/Resource';


describe('Resource', () => {

  it('should validate', () => {

    // when
    expect(() => {

      // given
      var o = Resource({ resourceType: 'Observation' });
    })

    //then
    .not.toThrow();
  });


  it('should have id and resourceType', () => {

    // when
    var o = Resource({ resourceType: 'Observation' });

    // then
    expect(o).toHaveProperty('resourceType');
    expect(o).toHaveProperty('id');
  });


  it('should error on wrong no resourceType', () => {

    // when
    expect(() => {

      // given
      var o = Resource({});
    })

    //then
    .toThrow();
  });


  it('should error on wrong id', () => {

    // when
    expect(() => {

      // given
      var o = Resource({ id: 1111 });
    })

    //then
    .toThrow();
  });



  it('should remove id', () => {

    // given
    var o = Resource({ id: '11', resourceType: 'Observation' });


    // when
    expect(() => {

      var o2 = Resource.update(o, { $remove: [ 'id' ] });

    })

    //then
    .not.toThrow();
  });


  it('should remove meta.lastUpdated', () => {

    // given
    var o = Resource({
      resourceType: 'Observation',
      meta: { lastUpdated: new Date().toISOString() }
    });


    // when
    var o2 = Resource.update(o, {
      meta: {
        $remove: [ 'lastUpdated' ]
      }
    });

    // then
    expect(o2.meta.lastUpdated).toBeUndefined();

  });

});
