var assert = require('chai').assert;
var request = require('supertest');

var container_url = 'http://localhost:8080/annotations/';

const MEDIA_TYPE = 'application/ld+json; profile="http://www.w3.org/ns/anno.jsonld"';

describe('MUSTs', function() {
  // Annotation Container Tests
  describe('4. Annotation Containers', function() {
    it.skip('An Annotation Server MUST provide one or more Containers');
    it('MUST end in a "/" character', function(done) {
      assert.isTrue(container_url[container_url.length-1] === '/');
      done();
    });

    container = request(container_url);
    it('MUST respond (by default) with an Annotation Container', function(done) {
      container
        .get('')
        .expect('Content-Type', MEDIA_TYPE)
        .expect(200, done);
    });
  });

  describe('4.1 Container Retrieval', function() {
    container = request(container_url);
    it('MUST support GET, HEAD, and OPTIONs methods', function(done) {
      container
        .get('')
        .expect('Allow', /GET/)
        .expect('Allow', /HEAD/)
        .expect('Allow', /OPTIONS/)
        .expect(200, done);
    });
  });

  // 4.1.1 Client Preferences are not tested here...
  // ...this *is* the client and we're testing the server

  describe('4.1.3 Responses with Annotations', function() {
    it('MUST use the paged collection model', function(done) {
      container
        .get('')
        .expect(function(res) {
          if ('items' in res.body) {
            throw new Error('AnnotationCollection MUST NOT contain items'
                + ' directly; only link to pages');
          }
        })
        .expect(200, done)
    });
    it('MUST also have a link to the first page of its contents using first',
      function(done) {
        container
          .get('')
          .expect(function(res) {
            if (!('first' in res.body)) {
              throw new Error('AnnotationCollection MUST reference at least the'
                  + ' first AnnotationPage');
            }
          })
          .expect(200, done)
      }
    );
    it.skip('MUST include a Content-Location header with the IRI as its value',
      function(done) {
      }
    );
    describe('Page Response', function() {
      it.skip('MUST have a link to the container that it is part of, using the partOf property',
        function(done) {
        }
      );
      // If it is not the first page...
      it.skip('MUST have a link to the previous page in the sequence, using the prev property',
        function(done) {
          // TODO: can the client know if it's the first page?
        }
      );
      // If it is not the last page...
      it.skip('MUST have a link to the next page in the sequence, using the next property',
        function(done) {
          // TODO: can the client know if it's the last page?
        }
      );
    });
  });
});

@@ -2063,29 +2063,24 @@
    );%0A    it
-.skip
 ('MUST inclu
@@ -2155,24 +2155,339 @@
 ion(done) %7B%0A
+        container%0A          .get('')%0A          .expect(function(res) %7B%0A            var cl = res.headers%5B'content-location'%5D;%0A            var id = res.body.id;%0A            if (cl !== id) %7B%0A              throw new Error('Content-Location and %60id%60 MUST match');%0A            %7D%0A          %7D)%0A          .expect(200, done)%0A
       %7D%0A    

Add Content-Location === IRI test