From 5d8d80755ecaa5fe8d9e8c4820dc11b63e3219f5 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Mon, 15 Aug 2016 13:11:46 +0200 Subject: [PATCH 1/3] [BREAKING] Change 'ResourceType' to 'Collection' --- lib/base-chips/_base-chips.js | 2 +- ...source_type.user.js => collection.user.js} | 0 .../field-types/single_reference.js | 8 +-- .../{resource-type.js => collection.js} | 48 +++++++-------- lib/main.js | 2 +- .../predefined-subjects/resources-subject.js | 4 +- ...subject.js => collection-field-subject.js} | 12 ++-- ...ction-subject.js => collection-subject.js} | 28 ++++----- .../subject-types/single-resource-subject.js | 4 +- ...ect.test.js => collection-subject.test.js} | 61 ++++++++++--------- .../single-resource-subject.test.js | 8 +-- 11 files changed, 89 insertions(+), 88 deletions(-) rename lib/base-chips/{resource_type.user.js => collection.user.js} (100%) rename lib/chip-types/{resource-type.js => collection.js} (80%) rename lib/subject/subject-types/{resource-type-field-subject.js => collection-field-subject.js} (68%) rename lib/subject/subject-types/{resource-type-collection-subject.js => collection-subject.js} (80%) rename tests/unit-tests/{resource-type-collection-subject.test.js => collection-subject.test.js} (87%) diff --git a/lib/base-chips/_base-chips.js b/lib/base-chips/_base-chips.js index 98b3da25..53c2b851 100644 --- a/lib/base-chips/_base-chips.js +++ b/lib/base-chips/_base-chips.js @@ -38,4 +38,4 @@ for(const i in field_types){ } -require("./resource_type.user.js"); +require("./collection.user.js"); diff --git a/lib/base-chips/resource_type.user.js b/lib/base-chips/collection.user.js similarity index 100% rename from lib/base-chips/resource_type.user.js rename to lib/base-chips/collection.user.js diff --git a/lib/base-chips/field-types/single_reference.js b/lib/base-chips/field-types/single_reference.js index 00f017ae..3162f7ce 100644 --- a/lib/base-chips/field-types/single_reference.js +++ b/lib/base-chips/field-types/single_reference.js @@ -1,12 +1,12 @@ "use strict"; const locreq = require("locreq")(__dirname); -const ResourceType = locreq("lib/chip-types/resource-type.js"); +const Collection = locreq("lib/chip-types/collection.js"); const Action = locreq("lib/action.js"); module.exports = { name: "single_reference", is_proper_value: function(accept, reject, context, params, new_value){ - const resource_type = new ResourceType(params.resource_type); + const resource_type = new Collection(params.resource_type); let resource_id; if (typeof new_value === "string"){ resource_id = new_value; @@ -31,7 +31,7 @@ module.exports = { if (decoded_value === undefined){ return undefined; } - const resource_type = new ResourceType(params.resource_type); + const resource_type = new Collection(params.resource_type); const resource_id = decoded_value; const action = new Action(["resources", resource_type.name, resource_id], "show"); return action.perform(context); @@ -42,7 +42,7 @@ module.exports = { filter_to_query: function(context, params, field_filter){ // treating filter as a query here if (typeof field_filter === "object"){ - const resource_type = new ResourceType(params.resource_type); + const resource_type = new Collection(params.resource_type); return context.run_action(["resources", resource_type.name], "show", {filter: field_filter}) .map(function(resource){ return resource.id; diff --git a/lib/chip-types/resource-type.js b/lib/chip-types/collection.js similarity index 80% rename from lib/chip-types/resource-type.js rename to lib/chip-types/collection.js index 6fb63db7..649aa77a 100644 --- a/lib/chip-types/resource-type.js +++ b/lib/chip-types/collection.js @@ -13,10 +13,10 @@ const AccessStrategy = require("./access-strategy.js"); const AccessStrategyType = locreq("lib/chip-types/access-strategy-type.js"); -const ResourceType = function(declaration){ +const Collection = function(declaration){ if (typeof declaration === "string"){ return ChipManager.get_chip("resource_type", declaration); - } else if (declaration instanceof ResourceType){ + } else if (declaration instanceof Collection){ return declaration; } Chip.call(this, "resource_type", declaration.name); @@ -29,7 +29,7 @@ const ResourceType = function(declaration){ }; this._process_declaration(declaration); }; -ResourceType.prototype._process_declaration = function(declaration){ +Collection.prototype._process_declaration = function(declaration){ if (declaration){ if (declaration.fields){ for (let i = 0; i < declaration.fields.length; i++){ @@ -44,7 +44,7 @@ ResourceType.prototype._process_declaration = function(declaration){ this.set_access_strategy(declaration.access_strategy); } }; -ResourceType.prototype.add_field = function(field_declaration){ +Collection.prototype.add_field = function(field_declaration){ const field_object = new Field(field_declaration, this); const field_name = field_object.name; if (!this.fields[field_name]){ @@ -54,13 +54,13 @@ ResourceType.prototype.add_field = function(field_declaration){ throw new Errors.DeveloperError("Duplicate field names: '" + field_name + "' in resource: '" + this.name + "'"); } }; -ResourceType.prototype.add_fields = function(field_declarations_array){ +Collection.prototype.add_fields = function(field_declarations_array){ for (const i in field_declarations_array){ const declaration = field_declarations_array[i]; this.add_field(declaration); } }; -ResourceType.prototype.has_previous_value_sensitive_fields = function(){ +Collection.prototype.has_previous_value_sensitive_fields = function(){ for (const field_name in this.fields){ if (this.fields[field_name].has_previous_value_sensitive_methods()){ return true; @@ -68,7 +68,7 @@ ResourceType.prototype.has_previous_value_sensitive_fields = function(){ } return false; }; -ResourceType.prototype.get_unknown_field_errors = function(values){ +Collection.prototype.get_unknown_field_errors = function(values){ const validation_errors = {}; for (const field_name in values){ if (this.fields[field_name] === undefined){ @@ -77,7 +77,7 @@ ResourceType.prototype.get_unknown_field_errors = function(values){ } return validation_errors; }; -ResourceType.prototype.get_missing_values_checker = function(values, assume_delete_value_on_missing_key, old_values){ +Collection.prototype.get_missing_values_checker = function(values, assume_delete_value_on_missing_key, old_values){ const self = this; if (assume_delete_value_on_missing_key){ return function(field_name){ @@ -89,7 +89,7 @@ ResourceType.prototype.get_missing_values_checker = function(values, assume_dele }; } }; -ResourceType.prototype.get_missing_field_values_errors = function(values, assume_delete_value_on_missing_key, old_values){ +Collection.prototype.get_missing_field_values_errors = function(values, assume_delete_value_on_missing_key, old_values){ const self = this; const errors = {}; const checker_fn = this.get_missing_values_checker(values, assume_delete_value_on_missing_key, old_values); @@ -101,7 +101,7 @@ ResourceType.prototype.get_missing_field_values_errors = function(values, assume return errors; }); }; -ResourceType.prototype.get_invalid_field_values_errors = function(context, values, old_values){ +Collection.prototype.get_invalid_field_values_errors = function(context, values, old_values){ const errors = {}; const promises = []; for (const field_name in values){ @@ -122,7 +122,7 @@ ResourceType.prototype.get_invalid_field_values_errors = function(context, value return errors; }); }; -ResourceType.prototype.validate_field_values = function(context, assume_delete_value_on_missing_key, new_values, old_values){ +Collection.prototype.validate_field_values = function(context, assume_delete_value_on_missing_key, new_values, old_values){ const self = this; const errors_array = [ self.get_unknown_field_errors(new_values), @@ -153,7 +153,7 @@ ResourceType.prototype.validate_field_values = function(context, assume_delete_v } }); }; -ResourceType.prototype.encode_field_values = function(context, body, old_body){ +Collection.prototype.encode_field_values = function(context, body, old_body){ const promises = {}; for (const field_name in body){ const current_value = body[field_name]; @@ -166,7 +166,7 @@ ResourceType.prototype.encode_field_values = function(context, body, old_body){ } return Promise.props(promises); }; -ResourceType.prototype.get_specification = function(with_validators){ +Collection.prototype.get_specification = function(with_validators){ // with_validators:boolean - whether to include validator functions in field descriptions. Warning! If set to true, the output is not serializable in JSON. const resource_type_specification = {}; for (const field_name in this.fields){ @@ -182,10 +182,10 @@ ResourceType.prototype.get_specification = function(with_validators){ }; return specification; }; -ResourceType.prototype.get_specification_with_validators = function(){ +Collection.prototype.get_specification_with_validators = function(){ return this.get_specification(true); }; -ResourceType.prototype.set_access_strategy = function(strategy_declaration){ +Collection.prototype.set_access_strategy = function(strategy_declaration){ if (typeof strategy_declaration === "string" || strategy_declaration instanceof AccessStrategyType || strategy_declaration instanceof Array){ @@ -199,10 +199,10 @@ ResourceType.prototype.set_access_strategy = function(strategy_declaration){ } } }; -ResourceType.prototype.get_access_strategy = function(action_name){ +Collection.prototype.get_access_strategy = function(action_name){ return this.access_strategy[action_name] || this.access_strategy["default"]; }; -ResourceType.prototype.has_large_data_fields = function(){ +Collection.prototype.has_large_data_fields = function(){ for (const i in this.fields){ const field = this.fields[i]; if (field.type.handles_large_data){ @@ -211,7 +211,7 @@ ResourceType.prototype.has_large_data_fields = function(){ } return false; }; -ResourceType.prototype.is_old_value_sensitive = function(method_name){ +Collection.prototype.is_old_value_sensitive = function(method_name){ for (const i in this.fields){ if (this.fields[i].type.is_old_value_sensitive(method_name)){ return true; @@ -219,7 +219,7 @@ ResourceType.prototype.is_old_value_sensitive = function(method_name){ } return false; }; -ResourceType.prototype.decode_values = function(context, values){ +Collection.prototype.decode_values = function(context, values){ const decoded_values = {}; for (const key in this.fields){ const value = values[key]; @@ -231,7 +231,7 @@ ResourceType.prototype.decode_values = function(context, values){ } return Promise.props(decoded_values); }; -ResourceType.prototype._format_decoded_values = function(context, decoded_values, format){ +Collection.prototype._format_decoded_values = function(context, decoded_values, format){ const formatted_values = clone(decoded_values); for (const field_name in formatted_values){ @@ -243,7 +243,7 @@ ResourceType.prototype._format_decoded_values = function(context, decoded_values } return Promise.props(formatted_values); }; -ResourceType.prototype._get_body = function(context, db_document, format){ +Collection.prototype._get_body = function(context, db_document, format){ const self = this; const decoded_values = this.decode_values(context, db_document.body); if (format){ @@ -254,7 +254,7 @@ ResourceType.prototype._get_body = function(context, db_document, format){ return decoded_values; } }; -ResourceType.prototype.get_resource_representation = ResourceType.prototype.decode_db_entry = function(context, db_document, format){ +Collection.prototype.get_resource_representation = Collection.prototype.decode_db_entry = function(context, db_document, format){ const representation = {}; representation.created_context = db_document.created_context; @@ -268,7 +268,7 @@ ResourceType.prototype.get_resource_representation = ResourceType.prototype.deco }); }; -ResourceType.prototype.check_if_action_is_allowed = function(context, action_name, resource_representation){ +Collection.prototype.check_if_action_is_allowed = function(context, action_name, resource_representation){ const access_strategy = this.get_access_strategy(action_name); return access_strategy.check(context, resource_representation) @@ -277,4 +277,4 @@ ResourceType.prototype.check_if_action_is_allowed = function(context, action_nam }); }; -module.exports = ResourceType; +module.exports = Collection; diff --git a/lib/main.js b/lib/main.js index f72554b9..bf12c80b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ Sealious.ChipTypes = { "Channel": require("./chip-types/channel.js"), "Datastore": require("./chip-types/datastore.js"), "FieldType": require("./chip-types/field-type.js"), - "ResourceType": require("./chip-types/resource-type.js") + "Collection": require("./chip-types/collection.js") }; // prefix Sealious.ChipTypes[chip_type_name] to Sealious[chip_type_name] diff --git a/lib/subject/predefined-subjects/resources-subject.js b/lib/subject/predefined-subjects/resources-subject.js index e630a468..5cb9836f 100644 --- a/lib/subject/predefined-subjects/resources-subject.js +++ b/lib/subject/predefined-subjects/resources-subject.js @@ -6,7 +6,7 @@ const Errors = locreq("lib/response/error.js"); const ChipManager = locreq("lib/chip-types/chip-manager.js"); const Subject = locreq("lib/subject/subject.js"); -const ResourceTypeCollection = require("../subject-types/resource-type-collection-subject.js"); +const CollectionSubject = locreq("lib/subject/subject-types/collection-subject.js"); const ResourcesSubject = function(){ @@ -17,7 +17,7 @@ const ResourcesSubject = function(){ const resource_types = ChipManager.get_chips_by_type("resource_type"); for (const resource_type_name in resource_types){ const resource_type = resource_types[resource_type_name]; - this.resource_collections[resource_type_name] = new ResourceTypeCollection(resource_type); + this.resource_collections[resource_type_name] = new CollectionSubject(resource_type); } }; diff --git a/lib/subject/subject-types/resource-type-field-subject.js b/lib/subject/subject-types/collection-field-subject.js similarity index 68% rename from lib/subject/subject-types/resource-type-field-subject.js rename to lib/subject/subject-types/collection-field-subject.js index d3ed8d25..8bbcc7e0 100644 --- a/lib/subject/subject-types/resource-type-field-subject.js +++ b/lib/subject/subject-types/collection-field-subject.js @@ -6,8 +6,8 @@ const merge = require("merge"); const Subject = locreq("lib/subject/subject.js"); const Errors = locreq("lib/response/error.js"); -const ResourceFieldTypeSubject = function(resource_type, resource_id, field_name){ - this.name = "ResourceFieldTypeSubject"; +const CollectionFieldSubject = function(resource_type, resource_id, field_name){ + this.name = "CollectionFieldSubject"; this.resource_type = resource_type; this.resource_id = resource_id; @@ -15,9 +15,9 @@ const ResourceFieldTypeSubject = function(resource_type, resource_id, field_name this.field_type = resource_type[field_name].type; }; -ResourceFieldTypeSubject.prototype = Object.create(Subject.prototype); +CollectionFieldSubject.prototype = Object.create(Subject.prototype); -ResourceFieldTypeSubject.prototype.perform_action = function(context, action_name, params){ +CollectionFieldSubject.prototype.perform_action = function(context, action_name, params){ params = params || {}; merge(params, { resource_id: this.resource_id, @@ -31,11 +31,11 @@ ResourceFieldTypeSubject.prototype.perform_action = function(context, action_nam } }; -ResourceFieldTypeSubject.prototype.get_child_subject = function(key){ +CollectionFieldSubject.prototype.get_child_subject = function(key){ const self = this; return Promise.try(function(){ return self.field_type.get_child_subject(key); }); }; -module.exports = ResourceFieldTypeSubject; +module.exports = CollectionFieldSubject; diff --git a/lib/subject/subject-types/resource-type-collection-subject.js b/lib/subject/subject-types/collection-subject.js similarity index 80% rename from lib/subject/subject-types/resource-type-collection-subject.js rename to lib/subject/subject-types/collection-subject.js index 5e1b009a..2346e152 100644 --- a/lib/subject/subject-types/resource-type-collection-subject.js +++ b/lib/subject/subject-types/collection-subject.js @@ -11,14 +11,14 @@ const ChipManager = locreq("lib/chip-types/chip-manager.js"); const Subject = locreq("lib/subject/subject.js"); const Errors = locreq("lib/response/error.js"); -const ResourceTypeCollection = function(resource_type){ +const CollectionSubject = function(resource_type){ this.resource_type = resource_type; - this.name = "ResourceTypeCollection"; + this.name = "Collection"; }; -ResourceTypeCollection.prototype = Object.create(Subject.prototype); +CollectionSubject.prototype = Object.create(Subject.prototype); -ResourceTypeCollection.prototype.__create_resource = function(datastore, resource_type, context, body){ +CollectionSubject.prototype.__create_resource = function(datastore, resource_type, context, body){ return resource_type.check_if_action_is_allowed(context, "create") .then(function(){ return resource_type.validate_field_values(context, true, body); @@ -39,12 +39,12 @@ ResourceTypeCollection.prototype.__create_resource = function(datastore, resourc }); }; -ResourceTypeCollection.prototype.create_resource = function(context, body){ +CollectionSubject.prototype.create_resource = function(context, body){ const self = this; - return ResourceTypeCollection.prototype.__create_resource(ChipManager.get_datastore_chip(), self.resource_type, context, body); + return CollectionSubject.prototype.__create_resource(ChipManager.get_datastore_chip(), self.resource_type, context, body); }; -ResourceTypeCollection.prototype.__preprocess_resource_filter = function(resource_type, context, filter){ +CollectionSubject.prototype.__preprocess_resource_filter = function(resource_type, context, filter){ filter = clone(filter) || {}; const expanded_filter = expandHash(filter); const processed_filter = {}; @@ -109,7 +109,7 @@ const get_output_options = function(resource_type, params){ return output_options; }; -ResourceTypeCollection.prototype.__list_resources = function(datastore, resource_type, context, params){ +CollectionSubject.prototype.__list_resources = function(datastore, resource_type, context, params){ if (params === undefined || params === null){ params = {}; } @@ -121,7 +121,7 @@ ResourceTypeCollection.prototype.__list_resources = function(datastore, resource return resource_type.check_if_action_is_allowed(context, "retrieve") .then(function(){ - return ResourceTypeCollection.prototype.__preprocess_resource_filter(resource_type, context, params.filter); + return CollectionSubject.prototype.__preprocess_resource_filter(resource_type, context, params.filter); }).then(function(body_filter){ const query = { type: resource_type.name, @@ -164,13 +164,13 @@ ResourceTypeCollection.prototype.__list_resources = function(datastore, resource }); }; -ResourceTypeCollection.prototype.list_resources = function(context, params){ +CollectionSubject.prototype.list_resources = function(context, params){ const datastore = ChipManager.get_datastore_chip(); const self = this; - return ResourceTypeCollection.prototype.__list_resources(datastore, self.resource_type, context, params); + return CollectionSubject.prototype.__list_resources(datastore, self.resource_type, context, params); }; -ResourceTypeCollection.prototype.perform_action = function(context, action_name, args){ +CollectionSubject.prototype.perform_action = function(context, action_name, args){ switch (action_name){ case "create": return this.create_resource(context, args); @@ -181,10 +181,10 @@ ResourceTypeCollection.prototype.perform_action = function(context, action_name, } }; -ResourceTypeCollection.prototype.get_child_subject = function(key){ +CollectionSubject.prototype.get_child_subject = function(key){ const resource_id = key; const single_resource_subject = new SingleResource(this.resource_type, resource_id); return Promise.resolve(single_resource_subject); }; -module.exports = ResourceTypeCollection; +module.exports = CollectionSubject; diff --git a/lib/subject/subject-types/single-resource-subject.js b/lib/subject/subject-types/single-resource-subject.js index 880ba413..a1115524 100644 --- a/lib/subject/subject-types/single-resource-subject.js +++ b/lib/subject/subject-types/single-resource-subject.js @@ -5,7 +5,7 @@ const Subject = locreq("lib/subject/subject.js"); const ChipManager = locreq("lib/chip-types/chip-manager.js"); const Errors = locreq("lib/response/error.js"); -const ResourceTypeFieldSubject = require("./resource-type-field-subject.js"); +const CollectionFieldSubject = require("./collection-field-subject.js"); const SingleResource = function(resource_type, resource_id){ this.resource_type = resource_type; @@ -113,7 +113,7 @@ SingleResource.prototype.perform_action = function(context, action_name, args){ SingleResource.prototype.get_child_subject = function(key){ if (this.resource_type.fields[key].type.is_subject){ - return new ResourceTypeFieldSubject(this.resource_type, this.resource_id, key); + return new CollectionFieldSubject(this.resource_type, this.resource_id, key); } }; diff --git a/tests/unit-tests/resource-type-collection-subject.test.js b/tests/unit-tests/collection-subject.test.js similarity index 87% rename from tests/unit-tests/resource-type-collection-subject.test.js rename to tests/unit-tests/collection-subject.test.js index c2cc502c..994cb39d 100644 --- a/tests/unit-tests/resource-type-collection-subject.test.js +++ b/tests/unit-tests/collection-subject.test.js @@ -1,4 +1,5 @@ "use strict"; +var locreq = require("locreq")(__dirname); var UUIDGenerator = require("shortid"); var equal = require("deep-equal"); @@ -7,7 +8,7 @@ var Promise = require("bluebird"); var assert_no_error = require("../util/assert-no-error.js"); var assert_error_type = require("../util/assert-error-type.js"); -var ResourceTypeCollectionSubject = require("../../lib/subject/subject-types/resource-type-collection-subject.js"); +var CollectionSubject = locreq("lib/subject/subject-types/collection-subject.js"); var SingleResource = require("../../lib/subject/subject-types/single-resource-subject.js"); module.exports = { @@ -16,7 +17,7 @@ module.exports = { describe(".create_resource", function(){ describe("should check access privilages, so it", function(){ - var rt_user1_only = new Sealious.ResourceType({ + var rt_user1_only = new Sealious.Collection({ name: "impossible_to_manipulate", fields: [], access_strategy: new Sealious.AccessStrategyType({ @@ -30,14 +31,14 @@ module.exports = { }) }); - var rt_user1_only_subject = new ResourceTypeCollectionSubject(rt_user1_only); + var rt_user1_only_subject = new CollectionSubject(rt_user1_only); it("should not allow creating a resource when the access strategy forbids it", function(done){ var result = rt_user1_only_subject.perform_action(new Sealious.Context(0, null, 2), "create", {}); assert_error_type(result, "permission", done); }); it("should allow creating a resource when the access strategy does not forbid it", function(done){ - var rt_user1_only_subject = new ResourceTypeCollectionSubject(rt_user1_only); + var rt_user1_only_subject = new CollectionSubject(rt_user1_only); var result = rt_user1_only_subject.perform_action(new Sealious.Context(0, null, 1), "create", {}); assert_no_error(result, done); @@ -46,7 +47,7 @@ module.exports = { }); describe("should check if provided values are valid, so it", function(){ - var rt_with_picky_field = new Sealious.ResourceType({ + var rt_with_picky_field = new Sealious.Collection({ fields: [{ name: "value", type: new Sealious.FieldType({ @@ -61,7 +62,7 @@ module.exports = { }] }); - var rt_with_picky_field_subject = new ResourceTypeCollectionSubject(rt_with_picky_field); + var rt_with_picky_field_subject = new CollectionSubject(rt_with_picky_field); it("should throw an error if they aren't", function(done){ var result = rt_with_picky_field_subject.perform_action(new Sealious.Context(), "create", {value: "incorrect"}); @@ -76,7 +77,7 @@ module.exports = { }); it("should store the resource body", function(done){ - var simple_rt_subject = new ResourceTypeCollectionSubject(new Sealious.ResourceType({ + var simple_rt_subject = new CollectionSubject(new Sealious.Collection({ fields: [ {name: "value1", type: "text"}, {name: "value2", type: "int"} @@ -97,7 +98,7 @@ module.exports = { }); it("should encode fields before sending them to datastore", function(done){ - var rt_with_fancy_field = new Sealious.ResourceType({ + var rt_with_fancy_field = new Sealious.Collection({ fields: [{ name: "value", type: new Sealious.FieldType({ @@ -108,7 +109,7 @@ module.exports = { }] }); - rt_with_fancy_field_subject = new ResourceTypeCollectionSubject(rt_with_fancy_field); + rt_with_fancy_field_subject = new CollectionSubject(rt_with_fancy_field); rt_with_fancy_field_subject.perform_action(new Sealious.Context(), "create", {value: "i_am"}) .then(function(resource_representation){ @@ -125,7 +126,7 @@ module.exports = { var context = new Sealious.Context(); var resource_type_name = "should create metadata for every newly created resource"; - var simple_rt_subject = new ResourceTypeCollectionSubject(new Sealious.ResourceType({name: resource_type_name})) + var simple_rt_subject = new CollectionSubject(new Sealious.Collection({name: resource_type_name})) .perform_action(context, "create", {}) .then(function(created_resource){ if (created_resource.id === undefined || created_resource.id === null){ @@ -149,7 +150,7 @@ module.exports = { it("should turn all filter values into {$eq: ...} query statements", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ fields: [ {name: "a", "type": "text"}, {name: "b", "type": "text"}, @@ -169,7 +170,7 @@ module.exports = { "c": {$eq: "f"} }; - var subject = new ResourceTypeCollectionSubject(rt); + var subject = new CollectionSubject(rt); subject._preprocess_resource_filter(new Sealious.Context(), filter) .then(function(result){ if (equal(result, expected_result, {strict: true})){ @@ -181,7 +182,7 @@ module.exports = { }); it("should skip values that do not correspond to the field names of the resource type and properly encode the others", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ fields: [ {name: "value", type: new Sealious.FieldType({ encode: function(context, params, value){ @@ -200,7 +201,7 @@ module.exports = { "value": {$eq: "foo_encoded"} }; - var subject = new ResourceTypeCollectionSubject(rt); + var subject = new CollectionSubject(rt); subject._preprocess_resource_filter(new Sealious.Context(), filter) .then(function(result){ if (equal(result, expected_result, {strict: true})){ @@ -215,7 +216,7 @@ module.exports = { describe(".list_resources", function(){ it("should throw a proper error when trying to list instances of resource type with a shallow access_strategy that disallows the context", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ fields: [{name: "value", type: "text"}], access_strategy: new Sealious.AccessStrategyType({ checker_function: function(context){ @@ -226,7 +227,7 @@ module.exports = { }) }); - var subject = new ResourceTypeCollectionSubject(rt); + var subject = new CollectionSubject(rt); var context = new Sealious.Context(0, null, 1); @@ -238,7 +239,7 @@ module.exports = { var resource_type_name = UUIDGenerator(10); - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ name: resource_type_name, fields: [{name: "who_can_access", type: "text"}], access_strategy: { @@ -258,7 +259,7 @@ module.exports = { }); - var subject = new ResourceTypeCollectionSubject(rt); + var subject = new CollectionSubject(rt); var accessible_amount = 4; var total_amount = 10; @@ -292,21 +293,21 @@ module.exports = { it("should only return resources of a given resource-type", function(done){ var resource_type_name1 = UUIDGenerator(10); - var rt1 = new Sealious.ResourceType({ + var rt1 = new Sealious.Collection({ name: resource_type_name1, fields: [{name: "value", type: "text"}] }); - var subject1 = new ResourceTypeCollectionSubject(rt1); + var subject1 = new CollectionSubject(rt1); var resource_type_name2 = UUIDGenerator(10); - var rt2 = new Sealious.ResourceType({ + var rt2 = new Sealious.Collection({ name: resource_type_name2, fields: [{name: "value", type: "text"}] }); - var subject2 = new ResourceTypeCollectionSubject(rt2); + var subject2 = new CollectionSubject(rt2); var accessible_amount = 4; var total_amount = 10; @@ -338,7 +339,7 @@ module.exports = { }); it("should throw an error when non-permission error is caught during filtering", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ name: UUIDGenerator(10), access_strategy: { default: "public", @@ -351,7 +352,7 @@ module.exports = { } }); - var subject = new ResourceTypeCollectionSubject(rt); + var subject = new CollectionSubject(rt); subject.perform_action(new Sealious.Context(), "create", {}) .then(function(){ @@ -370,7 +371,7 @@ module.exports = { }); it("should filter the results according to the 'filter' parameter", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ name: UUIDGenerator(10), fields: [{name: "value", type: "text"}] }); @@ -381,7 +382,7 @@ module.exports = { var promises = []; var p; - var subject = new ResourceTypeCollectionSubject(rt); + var subject = new CollectionSubject(rt); for (var i = 1; i <= accessible_amount; i++){ p = subject.perform_action(new Sealious.Context(), "create", {value: "1"}); @@ -410,11 +411,11 @@ module.exports = { describe(".perform_action", function(){ it("should throw an error when asked for non-existing action", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ name: UUIDGenerator(10) }); - var subject = new ResourceTypeCollectionSubject(rt); + var subject = new CollectionSubject(rt); try { subject.perform_action(new Sealious.Context(), "i_dont_exist"); @@ -431,9 +432,9 @@ module.exports = { describe(".get_child_subject", function(){ it("should return a SingleResource subject tied to a specific resource type and id", function(done){ - var rt = new Sealious.ResourceType({}); + var rt = new Sealious.Collection({}); - var subject = new ResourceTypeCollectionSubject(rt); + var subject = new CollectionSubject(rt); var resource_id = "resource_id"; diff --git a/tests/unit-tests/single-resource-subject.test.js b/tests/unit-tests/single-resource-subject.test.js index 7bcebbee..f0e6021b 100644 --- a/tests/unit-tests/single-resource-subject.test.js +++ b/tests/unit-tests/single-resource-subject.test.js @@ -15,7 +15,7 @@ module.exports = { var field_value = UUIDGenerator(10); - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ name: rt_name, fields: [{name: "value", type: "text"}] }); @@ -44,7 +44,7 @@ module.exports = { }); it("should throw an error when asked to show a resource when access strategy rejects the context", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ name: UUIDGenerator(10), fields: [{name: "value", type: "text"}], access_strategy: new Sealious.AccessStrategyType({ @@ -68,7 +68,7 @@ module.exports = { }); it("should throw an error when an item-sensitive access strategy rejects the 'show' method", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ name: UUIDGenerator(10), fields: [{name: "value", type: "text"}], access_strategy: { @@ -95,7 +95,7 @@ module.exports = { }); it("should not throw an error when an item-sensitive access strategy allows the 'show' method", function(done){ - var rt = new Sealious.ResourceType({ + var rt = new Sealious.Collection({ name: UUIDGenerator(10), fields: [{name: "value", type: "text"}], access_strategy: { From 7d1c246740beecbc517d8ab71de25babdbfbb648 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Mon, 15 Aug 2016 13:31:33 +0200 Subject: [PATCH 2/3] Change the integration tests branch in .travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 046ddf2b..7d79020c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ install: - cd ../ - git clone https://github.com/sealcode/sealious-integration-tests.git integration-tests - cd integration-tests +- git checkout alpha - npm install - npm link sealious - cd ../sealious From 0a3a3d7202e3edd862e657a8ac975402325cc3a8 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Tue, 16 Aug 2016 11:28:56 +0200 Subject: [PATCH 3/3] Empty commit to clear the Travis -> Coveralls.io pipe --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7d79020c..62994b9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ install: - git clone https://github.com/sealcode/sealious-integration-tests.git integration-tests - cd integration-tests - git checkout alpha -- npm install +- npm install . - npm link sealious - cd ../sealious after_success: