<commit_before>'use strict';

var expect = require('chai').expect;
var dataDriven = require('data-driven');

var hal = require('../');

describe('hal-lelujah', function () {

  describe('representation', function () {

    dataDriven([
      {value: undefined, description: 'undefined'},
      {value: null, description: 'null'},
      {value: {}, description: 'empty'}
    ], function () {
      it('builds empty representation out of {description} data object', function (context) {
        var repr = hal.representation(context.value);

        //noinspection JSUnresolvedVariable
        expect(repr.toJSON()).to.eql({});
      });
    });

    it('builds representation out of non-empty data object using direct mapping from the data object', function () {
      var source = {
        boolean: true,
        number: 7,
        string: 'property',
        object: {
          key: 'value'
        },
        array: [
          true,
          7,
          'property',
          {
            key: 'value'
          },
          []
        ]
      };
      var repr = hal.representation(source);

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql(source);
    });

    it('builds representation with the link given by relation name and hypertext reference', function () {
      var repr = hal.representation().link('next', 'scheme://user@server:port/relative/url?query=string&two=params#hash');

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql({
        _links: {
          next: {
            href: 'scheme://user@server:port/relative/url?query=string&two=params#hash'
          }
        }
      });
    });

    it('builds representation with the link given by relation name and link object', function () {
      var repr = hal.representation().link('next', {
        href: 'scheme://user@server:port/relative/url?query=string&two=params#hash',
        name: 'specialization',
        templated: true
      });

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql({
        _links: {
          next: {
            href: 'scheme://user@server:port/relative/url?query=string&two=params#hash',
            name: 'specialization',
            templated: true
          }
        }
      });
    });

    it('builds representation with the templated link given by relation name and hypertext reference', function () {
      var repr = hal.representation().templatedLink('next', 'scheme://user@server:port/relative/url?query=string&two=params#hash');

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql({
        _links: {
          next: {
            href: 'scheme://user@server:port/relative/url?query=string&two=params#hash',
            templated: true
          }
        }
      });
    });

    it('builds representation with the templated link given by relation name and link object', function () {
      var repr = hal.representation().templatedLink('next', {
        href: 'scheme://user@server:port/relative/url?query=string&two=params#hash',
        name: 'specialization',
        templated: false
      });

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql({
        _links: {
          next: {
            href: 'scheme://user@server:port/relative/url?query=string&two=params#hash',
            name: 'specialization',<commit_msg>Converting hypertext references into templated references in the tests that operate with templated links.<commit_after>'use strict';

var expect = require('chai').expect;
var dataDriven = require('data-driven');

var hal = require('../');

describe('hal-lelujah', function () {

  describe('representation', function () {

    dataDriven([
      {value: undefined, description: 'undefined'},
      {value: null, description: 'null'},
      {value: {}, description: 'empty'}
    ], function () {
      it('builds empty representation out of {description} data object', function (context) {
        var repr = hal.representation(context.value);

        //noinspection JSUnresolvedVariable
        expect(repr.toJSON()).to.eql({});
      });
    });

    it('builds representation out of non-empty data object using direct mapping from the data object', function () {
      var source = {
        boolean: true,
        number: 7,
        string: 'property',
        object: {
          key: 'value'
        },
        array: [
          true,
          7,
          'property',
          {
            key: 'value'
          },
          []
        ]
      };
      var repr = hal.representation(source);

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql(source);
    });

    it('builds representation with the link given by relation name and hypertext reference', function () {
      var repr = hal.representation().link('next', 'scheme://user@server:port/relative/url?query=string&two=params#hash');

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql({
        _links: {
          next: {
            href: 'scheme://user@server:port/relative/url?query=string&two=params#hash'
          }
        }
      });
    });

    it('builds representation with the link given by relation name and link object', function () {
      var repr = hal.representation().link('next', {
        href: 'scheme://user@server:port/relative/url?query=string&two=params#hash',
        name: 'specialization',
        templated: true
      });

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql({
        _links: {
          next: {
            href: 'scheme://user@server:port/relative/url?query=string&two=params#hash',
            name: 'specialization',
            templated: true
          }
        }
      });
    });

    it('builds representation with the templated link given by relation name and hypertext reference', function () {
      var repr = hal.representation().templatedLink('next', 'scheme://user@server:port/relative/url/{template-param}?query=string&two=params#hash');

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql({
        _links: {
          next: {
            href: 'scheme://user@server:port/relative/url/{template-param}?query=string&two=params#hash',
            templated: true
          }
        }
      });
    });

    it('builds representation with the templated link given by relation name and link object', function () {
      var repr = hal.representation().templatedLink('next', {
        href: 'scheme://user@server:port/relative/url/{template-param}?query=string&two=params#hash',
        name: 'specialization',
        templated: false
      });

      //noinspection JSUnresolvedVariable
      expect(repr.toJSON()).to.eql({
        _links: {
          next: {
            href: 'scheme://user@server:port/relative/url/{template-param}?query=string&two=params#hash',
            name: 'specialization',
{'fraction_non_alphanumeric': 0.1402368573079145, 'fraction_numerical': 0.0005777007510109763, 'mean_word_length': 2.4163788850518007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2701153', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1901, 'n_words': 408}