<commit_before>'use strict';

var SirenExtension = require('../../src/siren');

var expect = require('chai').expect;

describe('SirenExtension', function () {
  var addlMediaType = 'application/vnd.co.sirenformat+json';
  var ext;

  beforeEach(function() {
    ext = new SirenExtension([addlMediaType]);
  });

  describe('extension applicability', function() {
    it('should apply to application/vnd.siren+json content type', function() {
      expect(ext.applies({}, { 'content-type':  'application/vnd.siren+json' })).to.be.true;
    });

    it('should apply to application/vnd.siren+json content type with params', function() {
      expect(ext.applies({}, { 'content-type': 'application/vnd.siren+json; charset=utf-8' }, 200)).to.be.true;
    });

    it('should apply to a custom content type', function() {
      expect(ext.applies({}, { 'content-type':  addlMediaType })).to.be.true;
    });
  });

  describe('links parser', function() {
    it('should return the basic link', function() {
      var links = ext.linkParser({links: [ { rel: ['self'], href: '/orders/123' } ] }, {});
      expect(links.self[0].href).to.eql('/orders/123');
    });

    it('should return link for each relation in rel array', function() {
      var links = ext.linkParser({links: [ { rel: ['self', 'order'], href: '/orders/123' } ] }, {});
      expect(links.self[0].href).to.eql('/orders/123');
      expect(links.order[0].href).to.eql('/orders/123');
    });

    it('should return a link array for duplicate link rels', function() {
      var links = ext.linkParser({
        links: [
          { rel: ['self'], href: '/orders/123' },
          { rel: ['section'], href: '/orders?page=2' },
          { rel: ['section'], href: '/orders?page=3' }
        ]
      }, {});
      expect(links.section.length).to.eql(2);
      expect(links.section[0].href).to.eql('/orders?page=2');
    });

    it('should return a link array for duplicate embedded rels', function() {
      var links = ext.linkParser({
        entities: [
          { rel: ['section'], href: '/orders?page=2' },
          { rel: ['section'], href: '/orders?page=3' }
        ]
      }, {});
      expect(links.section.length).to.eql(2);
      expect(links.section[0].href).to.eql('/orders?page=2');
    });

    it('should include sub-entity links', function() {
      var links = ext.linkParser({
        links: [
          { rel: ['self'], href: '/orders/123' }
        ],
        entities: [
          {
            rel: ['order'],
            href: '/orders/123'
          }
        ]
      }, {});

      expect(links.order[0].href).to.eql('/orders/123');
    });

    it('should ignore full embedded entities', function() {
      var links = ext.linkParser({
        links: [
          { rel: ['self'], href: '/orders/123' }
        ],
        entities: [
          {
            rel: ['order'],
            properties: { status: 'completed' }
          }
        ]
      }, {});

      expect(links.order).to.not.exist;
    });
  });

  describe('the embedded parser', function() {
    it('should return the fully embedded entities', function() {
      var embedded = ext.embeddedParser({
        entities: [
          {
            rel: ['order'],
            links: [
              { rel: ['self'], href: '/orders/123' }
            ],
            title: 'My Order #123'
          }
        ]
      }, {});

      expect(embedded.order[0].title).to.eql('My Order #123');
    });
  });

  describe('data parser', function() {
    it('should return the properties field values', function() {
      var data = ext.dataParser({
        links: [ { rel: ['self'], href: '/orders/123' } ],
        properties: {
          name: '<NAME>'
        }
      }, {});

      expect(data).to.eql({ name: '<NAME>' });
    });

    it('should include the title, if present', function() {
      var data = ext.dataParser({
        links: [ { rel: ['self'], href: '/orders/123' } ],
        properties: {
          name: '<NAME>'
        },
        title: 'My Order #123'
      }, {});

      expect(data).to.eql({
        name: '<NAME>',
        title: 'My Order #123'
      });<commit_msg>One more Siren test case.<commit_after>'use strict';

var SirenExtension = require('../../src/siren');

var expect = require('chai').expect;

describe('SirenExtension', function () {
  var addlMediaType = 'application/vnd.co.sirenformat+json';
  var ext;

  beforeEach(function() {
    ext = new SirenExtension([addlMediaType]);
  });

  describe('extension applicability', function() {
    it('should apply to application/vnd.siren+json content type', function() {
      expect(ext.applies({}, { 'content-type':  'application/vnd.siren+json' })).to.be.true;
    });

    it('should apply to application/vnd.siren+json content type with params', function() {
      expect(ext.applies({}, { 'content-type': 'application/vnd.siren+json; charset=utf-8' }, 200)).to.be.true;
    });

    it('should apply to a custom content type', function() {
      expect(ext.applies({}, { 'content-type':  addlMediaType })).to.be.true;
    });
  });

  describe('links parser', function() {
    it('should return the basic link', function() {
      var links = ext.linkParser({links: [ { rel: ['self'], href: '/orders/123' } ] }, {});
      expect(links.self[0].href).to.eql('/orders/123');
    });

    it('should return link for each relation in rel array', function() {
      var links = ext.linkParser({links: [ { rel: ['self', 'order'], href: '/orders/123' } ] }, {});
      expect(links.self[0].href).to.eql('/orders/123');
      expect(links.order[0].href).to.eql('/orders/123');
    });

    it('should return a link array for duplicate link rels', function() {
      var links = ext.linkParser({
        links: [
          { rel: ['self'], href: '/orders/123' },
          { rel: ['section'], href: '/orders?page=2' },
          { rel: ['section'], href: '/orders?page=3' }
        ]
      }, {});
      expect(links.section.length).to.eql(2);
      expect(links.section[0].href).to.eql('/orders?page=2');
    });

    it('should return a link array for duplicate embedded rels', function() {
      var links = ext.linkParser({
        entities: [
          { rel: ['section'], href: '/orders?page=2' },
          { rel: ['section'], href: '/orders?page=3' }
        ]
      }, {});
      expect(links.section.length).to.eql(2);
      expect(links.section[0].href).to.eql('/orders?page=2');
    });

    it('should include sub-entity links', function() {
      var links = ext.linkParser({
        links: [
          { rel: ['self'], href: '/orders/123' }
        ],
        entities: [
          {
            rel: ['order'],
            href: '/orders/123'
          }
        ]
      }, {});

      expect(links.order[0].href).to.eql('/orders/123');
    });

    it('should ignore full embedded entities', function() {
      var links = ext.linkParser({
        links: [
          { rel: ['self'], href: '/orders/123' }
        ],
        entities: [
          {
            rel: ['order'],
            properties: { status: 'completed' }
          }
        ]
      }, {});

      expect(links.order).to.not.exist;
    });
  });

  describe('the embedded parser', function() {
    it('should return the fully embedded entities', function() {
      var embedded = ext.embeddedParser({
        entities: [
          {
            rel: ['order'],
            links: [
              { rel: ['self'], href: '/orders/123' }
            ],
            title: 'My Order #123'
          }
        ]
      }, {});

      expect(embedded.order[0].title).to.eql('My Order #123');
    });

    it('should ignore embedded links', function() {
      var embedded = ext.embeddedParser({
        entities: [
          {
            rel: ['order'],
            href: '/orders/123'
          }
        ]
      }, {});

      expect(embedded.order).to.not.exist;
    });
  });

  describe('data parser', function() {
    it('should return the properties field values', function() {
      var data = ext.dataParser({
        links: [ { rel: ['self'], href: '/orders/123' } ],
        properties: {
          name: '<NAME>'
        }
      }, {});

      expect(data).to.eql({ name: '<NAME>' });
    });

    it('should include the title, if present', function() {
      var data = ext.dataParser({
        links: [ { rel: ['self'], href: '/orders/123' } ],
        properties: {
          name: '<NAME>'
        },
        title: 'My Order #123'
      }, {});

      expect(data).to.eql({
        name: '<NAME>',
        title: 'My Order #123'
      });
{'fraction_non_alphanumeric': 0.19325475551406232, 'fraction_numerical': 0.01668806161745828, 'mean_word_length': 2.150735294117647, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2926946', 'n_tokens_mistral': 2737, 'n_tokens_neox': 2590, 'n_words': 558}