Exemple #1
0
describe('itemController storeFile method', function() {
  beforeEach(mongoose.removeAllCollections);
  beforeEach(nock.cleanAll);
  
  assertFunctionCallbacksError(storeFile, [{
    when: 'no user parameter provided',
    params: [undefined, wh.one('storage'), wh.jsonPath, wh.jsonData()],
    error: 'Parameter user undefined or null'
  }, {
    when: 'user parameter has no id property',
    params: [{ foo: 'bar' }, wh.one('storage'), wh.jsonPath, wh.jsonData()],
    error: 'Parameter user has no id property'
  }, {
    when: 'no storage parameter provided',
    params: [wh.one('user'), undefined, wh.jsonPath, wh.jsonData()],
    error: 'Parameter storage undefined or null'
  }, {
    when: 'storage parameter has no id property',
    params: [wh.one('user'), { foo: 'bar' }, wh.jsonPath, wh.jsonData()],
    error: 'Parameter storage has no id property'
  }, {
    when: 'storage parameter has no host property',
    params: [wh.one('user'), { id: 'bar' }, wh.jsonPath, wh.jsonData()],
    error: 'Parameter storage has no host property'
  }, {
    when: 'no path parameter provided',
    params: [wh.one('user'), wh.one('storage'), undefined, wh.jsonData()],
    error: 'Parameter path undefined or null'
  }, {
    when: 'path parameter not string',
    params: [wh.one('user'), wh.one('storage'), 3, wh.jsonData()],
    error: 'Parameter path is not a string'
  }, {
    when: 'path parameter lacks supported extension',
    params: [wh.one('user'), wh.one('storage'), '/hello.bar', wh.jsonData()],
    error: 'Parameter path extension indicates unsupported media type'
  }, {
    when: 'no data parameter provided',
    params: [wh.one('user'), wh.one('storage'), wh.jsonPath, undefined],
    error: 'Parameter data undefined or null'
  }, {
    when: 'data parameter not object or buffer',
    params: [wh.one('user'), wh.one('storage'), wh.jsonPath, 3],
    error: 'Parameter data is not one of the supported types: buffer, object'
  }, {
    when: 'jpg path matched with json data',
    params: [wh.one('user'), wh.one('storage'), wh.jpegPath, wh.jsonData()],
    error: 'Path parameter with jpg extension not provided with binary data'
  }, {
    when: 'json path matched with buffer data',
    params: [wh.one('user'), wh.one('storage'), wh.jsonPath, wh.jpegData],
    error: 'Path parameter with json extension not provided with parseable data'
  }, {
    when: 'userStorageAuth.storageToken invalid',
    params: [wh.one('user'), wh.one('storage'), wh.jsonPath, wh.jsonData()],
    error: 'Failed to make successful request. HTTP status code: 401',
    before: function(done) {
      wh.oneSaved('userStorageAuth', {
        user: this.params[0],
        storage: this.params[1]
      }, (error, userStorageAuth) => {
        nock.postStorage(this.params[1], userStorageAuth, 401);
        done();
      });
    }
  }]);

  assertFunctionCallbacksResult(storeFile, [{
    when: 'provided JSON data',
    params: [wh.one('user'), wh.one('storage'), wh.jsonPath, wh.jsonData()],
    result: { size: wh.bytes, path_lower: wh.jsonPath },
    before: before(wh.jsonPath)
  }, {
    when: 'provided buffer data',
    params: [wh.one('user'), wh.one('storage'), wh.jpegPath, wh.jpegData],
    result: { size: wh.bytes, path_lower: wh.jpegPath },
    before: before(wh.jpegPath)
  }]);
});
Exemple #2
0
describe('jsonapi', () => {
  assertObjectHasProperties('jsonapi', jsonapi, [
    'allowed',
    'compiledQueryConditions',
    'modelQueryConditions',
    'routeModelDeleteObjectResource',
    'routeModelGetObjectResource',
    'routeModelGetObjectsResource',
    'routeModelPatchObjectResource',
    'routeModelPostObjectResource',
    'routeModelResource',
    'routeModelResources',
    'routeResource',
    'saveRelationshipsToDocument',
    'validateQueryData',
    'validateRequestBody'
  ]);

  var method = 'get';
  var model = {
    jsonapi: {
      get: 'public'
    },
    modelId: () => {
      return 'testModelId';
    }
  };
  var req = {};

  assertFunctionThrowsError('jsonapi.modelQueryConditions', jsonapi.modelQueryConditions, [{
    when: 'no req parameter provided',
    params: [undefined, model, method],
    error: 'Parameter req undefined or null'
  }, {
    when: 'no model parameter provided',
    params: [req, undefined, method],
    error: 'Parameter model undefined or null'
  }, {
    when: 'no method parameter provided',
    params: [req, model, undefined],
    error: 'Parameter method undefined or null'
  }, {
    when: 'model parameter has no jsonapi property',
    params: [req, model, method],
    error: 'Parameter model has no jsonapi property', 
    before: function(done) {
      var model = Object.assign({}, this.params[1]);
      delete model.jsonapi;
      this.params[1] = model;
      done();
    }
  }]);

  assertFunctionCallbacksResult('jsonapi.modelQueryConditions', jsonapi.modelQueryConditions, [{
    when: 'model with no jsonapi[method] property provided',
    params: [req, model, method],
    result: {},
    before: function(done) {
      var model = Object.assign({}, this.params[1]);
      delete model.jsonapi[this.params[2]];
      this.params[1] = model;
      done();
    }
  }]);

  it('responds with JSON API content type header');
  it('sends 415 status when receiving requests with modified JSON API content type header');
  it('sends 406 status when receiving requests with modified JSON API accept header');
  it('responds with jsonapi object');
  it('routes GET requests for resource objects');
  it('routes GET requests for resource object');
  it('routes POST requests for resource object');
  it('routes DELETE requests for resource object');

  it('responds with errors');
});