diff --git a/README.md b/README.md index 68fc0e7..b39affa 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ client.send(new AddDetailView, var recombee = require('recombee-api-client'); var rqs = recombee.requests; -var client = new recombee.ApiClient('--my-database-id--', '--db-private-token--'); +var client = new recombee.ApiClient('--my-database-id--', '--db-private-token--', {region: 'us-west'}); // Prepare some userIDs and itemIDs const NUM = 100; @@ -96,7 +96,7 @@ client.send(new rqs.Batch(purchases)) var recombee = require('recombee-api-client'); var rqs = recombee.requests; -var client = new recombee.ApiClient('--my-database-id--', '--db-private-token--'); +var client = new recombee.ApiClient('--my-database-id--', '--db-private-token--', {region: 'ap-se'}); const NUM = 100; // We will use computers as items in this example diff --git a/lib/api-client.js b/lib/api-client.js index f912714..b7a3e80 100644 --- a/lib/api-client.js +++ b/lib/api-client.js @@ -1,8 +1,7 @@ 'use strict'; const jsSHA = require("jssha"); -const rp = require('request-promise'); -const rp_errors = require('request-promise/errors'); +const got = require('got'); const api_errors = require('./errors'); const requests = require('./requests'); @@ -17,15 +16,17 @@ class ApiClient { * Construct the client * @param {string} databaseId - ID of your database * @param {string} secretToken - Corresponding secret token - * @param {boolean} alwaysUseHttps - If true, all requests are sent using HTTPS (default: true) * @param {Object} options - Other custom options */ - constructor (databaseId, token, alwaysUseHttps, options) { + constructor (databaseId, token, options) { this.databaseId = databaseId; this.token = token; - this.alwaysUseHttps = (alwaysUseHttps === undefined) ? true : alwaysUseHttps; this.options = options || {}; - this.baseUri = process.env.RAPI_URI || this.options.baseUri || 'rapi.recombee.com'; + + if (Object.getPrototypeOf(this.options) !== Object.prototype) throw new Error(`options must be given as an Object (${this.options} given instead)`); + + this.protocol = this.options.protocol || 'https'; + this.baseUri = this._getBaseUri() } /** @@ -41,50 +42,69 @@ class ApiClient { let url = this._buildRequestUrl(request); let options = { method: request.method, - uri: url, + url: url, headers: {'Accept': 'application/json', 'Content-Type': 'application/json', - 'User-Agent': 'recombee-node-api-client/3.2.0'}, - timeout: request.timeout, - resolveWithFullResponse: true, - json: true + 'User-Agent': 'recombee-node-api-client/4.0.0'}, + timeout: request.timeout }; - if (this.options.proxy) - options.proxy = this.options.proxy; - - if (request.bodyParameters()) - options.body = request.bodyParameters(); + if (Object.entries(request.bodyParameters()).length > 0) + options.json = request.bodyParameters(); - return rp(options) - .then(this._parseResponse) + return got(options) + .json() .then((response)=> { return new Promise( (resolve) => { if (callback) { return callback(null, response); } return resolve(response); }); }) - .catch(rp_errors.StatusCodeError,((error) => { - throw new api_errors.ResponseError(request, error.statusCode, error.message); + .catch((error) => { + if (error instanceof got.HTTPError) { + error = new api_errors.ResponseError(request, error.response.statusCode, error.response.body); } - )) - .catch(rp_errors.RequestError,((error) => { - if(error.cause.code === 'ETIMEDOUT' || error.cause.code === 'ESOCKETTIMEDOUT') - throw new api_errors.TimeoutError(request, error); - throw error; + else if (error instanceof got.RequestError) { + if(error.code === 'ETIMEDOUT' || error.code === 'ESOCKETTIMEDOUT') { + error = new api_errors.TimeoutError(request, error); + } } - )) - .catch((error) => { if (callback) {return callback(error)}; throw error; }); } + _getRegionalBaseUri(region) { + const uri = { + 'ap-se': 'rapi-ap-se.recombee.com', + 'ca-east': 'rapi-ca-east.recombee.com', + 'eu-west': 'rapi-eu-west.recombee.com', + 'us-west': 'rapi-us-west.recombee.com' + }[region.toLowerCase()]; + + if (uri === undefined) { + throw new Error(`Region "${region}" is unknown. You may need to update the version of the SDK.`) + } + + return uri; + } + + _getBaseUri() { + let baseUri = process.env.RAPI_URI || this.options.baseUri; + if (this.options.region) { + if (baseUri) { + throw new Error('baseUri and region cannot be specified at the same time'); + } + baseUri = this._getRegionalBaseUri(this.options.region); + } + return baseUri || 'rapi.recombee.com'; + } + _buildRequestUrl(request) { - let protocol = (request.ensureHttps || this.alwaysUseHttps) ? 'https' : 'http'; + let usedProtocol = (request.ensureHttps) ? 'https' : this.protocol; let reqUrl = request.path + this._encodeRequestQueryParams(request); let signedUrl = this._signUrl(reqUrl); - return protocol + '://' + this.baseUri + signedUrl; + return usedProtocol + '://' + this.baseUri + signedUrl; } _encodeRequestQueryParams(request) { @@ -161,14 +181,6 @@ class ApiClient { }); } - _parseResponse(response) { - return new Promise( - function (resolve, reject) { - resolve(response.body); - } - ); - } - _signUrl (req_part) { let url = '/' + this.databaseId + req_part; url += (req_part.indexOf("?") == -1 ? "?" : "&" ) + "hmac_timestamp=" + parseInt(new Date().getTime() / 1000); diff --git a/lib/requests/delete-item.js b/lib/requests/delete-item.js index c948d31..d203c11 100644 --- a/lib/requests/delete-item.js +++ b/lib/requests/delete-item.js @@ -8,7 +8,7 @@ const rqs = require("./request"); /** * Deletes an item of given `itemId` from the catalog. * If there are any *purchases*, *ratings*, *bookmarks*, *cart additions* or *detail views* of the item present in the database, they will be deleted in cascade as well. Also, if the item is present in some *series*, it will be removed from all the *series* where present. - * If an item becomes obsolete/no longer available, it is often meaningful to keep it in the catalog (along with all the interaction data, which are very useful), and only exclude the item from recommendations. In such a case, use [ReQL filter](https://docs.recombee.com/reql.html) instead of deleting the item completely. + * If an item becomes obsolete/no longer available, it is meaningful to keep it in the catalog (along with all the interaction data, which are very useful), and **only exclude the item from recommendations**. In such a case, use [ReQL filter](https://docs.recombee.com/reql.html) instead of deleting the item completely. */ class DeleteItem extends rqs.Request { diff --git a/lib/requests/delete-more-items.js b/lib/requests/delete-more-items.js new file mode 100644 index 0000000..65b399c --- /dev/null +++ b/lib/requests/delete-more-items.js @@ -0,0 +1,44 @@ +/* + This file is auto-generated, do not edit +*/ + +'use strict'; +const rqs = require("./request"); + +/** + * Delete all the items that pass the filter. + * If an item becomes obsolete/no longer available, it is meaningful to **keep it in the catalog** (along with all the interaction data, which are very useful), and **only exclude the item from recommendations**. In such a case, use [ReQL filter](https://docs.recombee.com/reql.html) instead of deleting the item completely. + */ +class DeleteMoreItems extends rqs.Request { + + /** + * Construct the request + * @param {string} filter - A [ReQL](https://docs.recombee.com/reql.html) expression, which return `true` for the items that shall be updated. + */ + constructor(filter) { + super('DELETE', '/more-items/', 1000, false); + this.filter = filter; + } + + /** + * Get body parameters + * @return {Object} The values of body parameters (name of parameter: value of the parameter) + */ + bodyParameters() { + let params = {}; + params.filter = this.filter; + + return params; + } + + /** + * Get query parameters + * @return {Object} The values of query parameters (name of parameter: value of the parameter) + */ + queryParameters() { + let params = {}; + return params; + } +} + +exports.DeleteMoreItems = DeleteMoreItems diff --git a/lib/requests/delete-user.js b/lib/requests/delete-user.js index adf92c6..7da7075 100644 --- a/lib/requests/delete-user.js +++ b/lib/requests/delete-user.js @@ -13,7 +13,7 @@ class DeleteUser extends rqs.Request { /** * Construct the request - * @param {string} userId - ID of the user to be added. + * @param {string} userId - ID of the user to be deleted. */ constructor(userId) { super('DELETE', `/users/${userId}`, 1000, false); diff --git a/lib/requests/index.js b/lib/requests/index.js index 4d91e11..7b7574a 100644 --- a/lib/requests/index.js +++ b/lib/requests/index.js @@ -12,6 +12,8 @@ exports.AddItemProperty = require("./add-item-property").AddItemProperty; exports.DeleteItemProperty = require("./delete-item-property").DeleteItemProperty; exports.GetItemPropertyInfo = require("./get-item-property-info").GetItemPropertyInfo; exports.ListItemProperties = require("./list-item-properties").ListItemProperties; +exports.UpdateMoreItems = require("./update-more-items").UpdateMoreItems; +exports.DeleteMoreItems = require("./delete-more-items").DeleteMoreItems; exports.AddSeries = require("./add-series").AddSeries; exports.DeleteSeries = require("./delete-series").DeleteSeries; exports.ListSeries = require("./list-series").ListSeries; @@ -63,8 +65,6 @@ exports.RecommendItemsToItem = require("./recommend-items-to-item").RecommendIte exports.RecommendNextItems = require("./recommend-next-items").RecommendNextItems; exports.RecommendUsersToUser = require("./recommend-users-to-user").RecommendUsersToUser; exports.RecommendUsersToItem = require("./recommend-users-to-item").RecommendUsersToItem; -exports.UserBasedRecommendation = require("./user-based-recommendation").UserBasedRecommendation; -exports.ItemBasedRecommendation = require("./item-based-recommendation").ItemBasedRecommendation; exports.SearchItems = require("./search-items").SearchItems; exports.AddSearchSynonym = require("./add-search-synonym").AddSearchSynonym; exports.ListSearchSynonyms = require("./list-search-synonyms").ListSearchSynonyms; diff --git a/lib/requests/item-based-recommendation.js b/lib/requests/item-based-recommendation.js deleted file mode 100644 index 6cdc43b..0000000 --- a/lib/requests/item-based-recommendation.js +++ /dev/null @@ -1,187 +0,0 @@ -/* - This file is auto-generated, do not edit -*/ - -'use strict'; -const rqs = require("./request"); - -/** - * Recommends set of items that are somehow related to one given item, *X*. Typical scenario for using item-based recommendation is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Item-recommendation request gives you Top-N such items, optionally taking the target user *A* into account. - * It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters. - * @deprecated Deprecated since version 2.0.0. Use RecommendItemsToItem request instead. - */ -class ItemBasedRecommendation extends rqs.Request { - - /** - * Construct the request - * @param {string} itemId - ID of the item for which the recommendations are to be generated. - * @param {number} count - Number of items to be recommended (N for the top-N recommendation). - * @param {Object} optional - Optional parameters given as an object with structure name of the parameter: value - * - Allowed parameters: - * - *targetUserId* - * - Type: string - * - Description: ID of the user who will see the recommendations. - * Specifying the *targetUserId* is beneficial because: - * * It makes the recommendations personalized - * * Allows the calculation of Actions and Conversions in the graphical user interface, - * as Recombee can pair the user who got recommendations and who afterwards viewed/purchased an item. - * For the above reasons, we encourage you to set the *targetUserId* even for anonymous/unregistered users (i.e. use their session ID). - * - *userImpact* - * - Type: number - * - Description: If *targetUserId* parameter is present, the recommendations are biased towards the user given. Using *userImpact*, you may control this bias. For an extreme case of `userImpact=0.0`, the interactions made by the user are not taken into account at all (with the exception of history-based blacklisting), for `userImpact=1.0`, you'll get user-based recommendation. The default value is `0`. - * - *filter* - * - Type: string - * - Description: Boolean-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to filter recommended items based on the values of their attributes. - * - *booster* - * - Type: string - * - Description: Number-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to boost recommendation rate of some items based on the values of their attributes. - * - *allowNonexistent* - * - Type: boolean - * - Description: Instead of causing HTTP 404 error, returns some (non-personalized) recommendations if either item of given *itemId* or user of given *targetUserId* does not exist in the database. It creates neither of the missing entities in the database. - * - *cascadeCreate* - * - Type: boolean - * - Description: If item of given *itemId* or user of given *targetUserId* doesn't exist in the database, it creates the missing enity/entities and returns some (non-personalized) recommendations. This allows for example rotations in the following recommendations for the user of given *targetUserId*, as the user will be already known to the system. - * - *scenario* - * - Type: string - * - Description: Scenario defines a particular application of recommendations. It can be for example "homepage", "cart" or "emailing". You can see each scenario in the UI separately, so you can check how well each application performs. The AI which optimizes models in order to get the best results may optimize different scenarios separately, or even use different models in each of the scenarios. - * - *returnProperties* - * - Type: boolean - * - Description: With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used for easy displaying of the recommended items to the user. - * Example response: - * ``` - * [ - * { - * "itemId": "tv-178", - * "description": "4K TV with 3D feature", - * "categories": ["Electronics", "Televisions"], - * "price": 342, - * "url": "myshop.com/tv-178" - * }, - * { - * "itemId": "mixer-42", - * "description": "Stainless Steel Mixer", - * "categories": ["Home & Kitchen"], - * "price": 39, - * "url": "myshop.com/mixer-42" - * } - * ] - * ``` - * - *includedProperties* - * - Type: string[] - * - Description: Allows to specify, which properties should be returned when `returnProperties=true` is set. The properties are given as a comma-separated list. - * Example response for `includedProperties=description,price`: - * ``` - * [ - * { - * "itemId": "tv-178", - * "description": "4K TV with 3D feature", - * "price": 342 - * }, - * { - * "itemId": "mixer-42", - * "description": "Stainless Steel Mixer", - * "price": 39 - * } - * ] - * ``` - * - *diversity* - * - Type: number - * - Description: **Expert option** Real number from [0.0, 1.0] which determines how much mutually dissimilar should the recommended items be. The default value is 0.0, i.e., no diversification. Value 1.0 means maximal diversification. - * - *minRelevance* - * - Type: string - * - Description: **Expert option** If the *targetUserId* is provided: Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it. - * - *rotationRate* - * - Type: number - * - Description: **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.01`. - * - *rotationTime* - * - Type: number - * - Description: **Expert option** If the *targetUserId* is provided: Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`. - * - *expertSettings* - * - Type: - * - Description: Dictionary of custom options. - */ - constructor(itemId, count, optional) { - super('POST', `/items/${itemId}/recomms/`, 3000, false); - this.itemId = itemId; - this.count = count; - optional = optional || {}; - this.targetUserId = optional.targetUserId; - this.userImpact = optional.userImpact; - this.filter = optional.filter; - this.booster = optional.booster; - this.allowNonexistent = optional.allowNonexistent; - this.cascadeCreate = optional.cascadeCreate; - this.scenario = optional.scenario; - this.returnProperties = optional.returnProperties; - this.includedProperties = optional.includedProperties; - this.diversity = optional.diversity; - this.minRelevance = optional.minRelevance; - this.rotationRate = optional.rotationRate; - this.rotationTime = optional.rotationTime; - this.expertSettings = optional.expertSettings; - } - - /** - * Get body parameters - * @return {Object} The values of body parameters (name of parameter: value of the parameter) - */ - bodyParameters() { - let params = {}; - params.count = this.count; - - if(this.targetUserId !== undefined) - params.targetUserId = this.targetUserId; - - if(this.userImpact !== undefined) - params.userImpact = this.userImpact; - - if(this.filter !== undefined) - params.filter = this.filter; - - if(this.booster !== undefined) - params.booster = this.booster; - - if(this.allowNonexistent !== undefined) - params.allowNonexistent = this.allowNonexistent; - - if(this.cascadeCreate !== undefined) - params.cascadeCreate = this.cascadeCreate; - - if(this.scenario !== undefined) - params.scenario = this.scenario; - - if(this.returnProperties !== undefined) - params.returnProperties = this.returnProperties; - - if(this.includedProperties !== undefined) - params.includedProperties = this.includedProperties; - - if(this.diversity !== undefined) - params.diversity = this.diversity; - - if(this.minRelevance !== undefined) - params.minRelevance = this.minRelevance; - - if(this.rotationRate !== undefined) - params.rotationRate = this.rotationRate; - - if(this.rotationTime !== undefined) - params.rotationTime = this.rotationTime; - - if(this.expertSettings !== undefined) - params.expertSettings = this.expertSettings; - - return params; - } - - /** - * Get query parameters - * @return {Object} The values of query parameters (name of parameter: value of the parameter) - */ - queryParameters() { - let params = {}; - return params; - } -} - -exports.ItemBasedRecommendation = ItemBasedRecommendation diff --git a/lib/requests/recommend-items-to-user.js b/lib/requests/recommend-items-to-user.js index 35aa926..f6c84e5 100644 --- a/lib/requests/recommend-items-to-user.js +++ b/lib/requests/recommend-items-to-user.js @@ -110,7 +110,7 @@ class RecommendItemsToUser extends rqs.Request { * - Description: **Expert option** Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested relevance, and may return less than *count* items when there is not enough data to fulfill it. * - *rotationRate* * - Type: number - * - Description: **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.1`. + * - Description: **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0`. * - *rotationTime* * - Type: number * - Description: **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`. diff --git a/lib/requests/update-more-items.js b/lib/requests/update-more-items.js new file mode 100644 index 0000000..732f824 --- /dev/null +++ b/lib/requests/update-more-items.js @@ -0,0 +1,53 @@ +/* + This file is auto-generated, do not edit +*/ + +'use strict'; +const rqs = require("./request"); + +/** + * Update (some) property values of all the items that pass the filter. + * Example: *Setting all the items that are older than a week as unavailable* + * ``` + * { + * "filter": "'releaseDate' < now() - 7*24*3600", + * "changes": {"available": false} + * } + * ``` + */ +class UpdateMoreItems extends rqs.Request { + + /** + * Construct the request + * @param {string} filter - A [ReQL](https://docs.recombee.com/reql.html) expression, which return `true` for the items that shall be updated. + * @param {} changes - A dictionary where the keys are properties which shall be updated. + */ + constructor(filter, changes) { + super('POST', '/more-items/', 1000, false); + this.filter = filter; + this.changes = changes; + } + + /** + * Get body parameters + * @return {Object} The values of body parameters (name of parameter: value of the parameter) + */ + bodyParameters() { + let params = {}; + params.filter = this.filter; + params.changes = this.changes; + + return params; + } + + /** + * Get query parameters + * @return {Object} The values of query parameters (name of parameter: value of the parameter) + */ + queryParameters() { + let params = {}; + return params; + } +} + +exports.UpdateMoreItems = UpdateMoreItems diff --git a/lib/requests/user-based-recommendation.js b/lib/requests/user-based-recommendation.js deleted file mode 100644 index 9c18a38..0000000 --- a/lib/requests/user-based-recommendation.js +++ /dev/null @@ -1,168 +0,0 @@ -/* - This file is auto-generated, do not edit -*/ - -'use strict'; -const rqs = require("./request"); - -/** - * Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user. - * It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters. - * @deprecated Deprecated since version 2.0.0. Use RecommendItemsToUser request instead. - */ -class UserBasedRecommendation extends rqs.Request { - - /** - * Construct the request - * @param {string} userId - ID of the user for whom the personalized recommendations are to be generated. - * @param {number} count - Number of items to be recommended (N for the top-N recommendation). - * @param {Object} optional - Optional parameters given as an object with structure name of the parameter: value - * - Allowed parameters: - * - *filter* - * - Type: string - * - Description: Boolean-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to filter recommended items based on the values of their attributes. - * - *booster* - * - Type: string - * - Description: Number-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to boost recommendation rate of some items based on the values of their attributes. - * - *allowNonexistent* - * - Type: boolean - * - Description: If the user does not exist in the database, returns a list of non-personalized recommendations instead of causing HTTP 404 error. It doesn't create the user in the database. - * - *cascadeCreate* - * - Type: boolean - * - Description: If the user does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows for example rotations in the following recommendations for that user, as the user will be already known to the system. - * - *scenario* - * - Type: string - * - Description: Scenario defines a particular application of recommendations. It can be for example "homepage", "cart" or "emailing". You can see each scenario in the UI separately, so you can check how well each application performs. The AI which optimizes models in order to get the best results may optimize different scenarios separately, or even use different models in each of the scenarios. - * - *returnProperties* - * - Type: boolean - * - Description: With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used for easy displaying of the recommended items to the user. - * Example response: - * ``` - * [ - * { - * "itemId": "tv-178", - * "description": "4K TV with 3D feature", - * "categories": ["Electronics", "Televisions"], - * "price": 342, - * "url": "myshop.com/tv-178" - * }, - * { - * "itemId": "mixer-42", - * "description": "Stainless Steel Mixer", - * "categories": ["Home & Kitchen"], - * "price": 39, - * "url": "myshop.com/mixer-42" - * } - * ] - * ``` - * - *includedProperties* - * - Type: string[] - * - Description: Allows to specify, which properties should be returned when `returnProperties=true` is set. The properties are given as a comma-separated list. - * Example response for `includedProperties=description,price`: - * ``` - * [ - * { - * "itemId": "tv-178", - * "description": "4K TV with 3D feature", - * "price": 342 - * }, - * { - * "itemId": "mixer-42", - * "description": "Stainless Steel Mixer", - * "price": 39 - * } - * ] - * ``` - * - *diversity* - * - Type: number - * - Description: **Expert option** Real number from [0.0, 1.0] which determines how much mutually dissimilar should the recommended items be. The default value is 0.0, i.e., no diversification. Value 1.0 means maximal diversification. - * - *minRelevance* - * - Type: string - * - Description: **Expert option** Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it. - * - *rotationRate* - * - Type: number - * - Description: **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.1`. - * - *rotationTime* - * - Type: number - * - Description: **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`. - * - *expertSettings* - * - Type: - * - Description: Dictionary of custom options. - */ - constructor(userId, count, optional) { - super('POST', `/users/${userId}/recomms/`, 3000, false); - this.userId = userId; - this.count = count; - optional = optional || {}; - this.filter = optional.filter; - this.booster = optional.booster; - this.allowNonexistent = optional.allowNonexistent; - this.cascadeCreate = optional.cascadeCreate; - this.scenario = optional.scenario; - this.returnProperties = optional.returnProperties; - this.includedProperties = optional.includedProperties; - this.diversity = optional.diversity; - this.minRelevance = optional.minRelevance; - this.rotationRate = optional.rotationRate; - this.rotationTime = optional.rotationTime; - this.expertSettings = optional.expertSettings; - } - - /** - * Get body parameters - * @return {Object} The values of body parameters (name of parameter: value of the parameter) - */ - bodyParameters() { - let params = {}; - params.count = this.count; - - if(this.filter !== undefined) - params.filter = this.filter; - - if(this.booster !== undefined) - params.booster = this.booster; - - if(this.allowNonexistent !== undefined) - params.allowNonexistent = this.allowNonexistent; - - if(this.cascadeCreate !== undefined) - params.cascadeCreate = this.cascadeCreate; - - if(this.scenario !== undefined) - params.scenario = this.scenario; - - if(this.returnProperties !== undefined) - params.returnProperties = this.returnProperties; - - if(this.includedProperties !== undefined) - params.includedProperties = this.includedProperties; - - if(this.diversity !== undefined) - params.diversity = this.diversity; - - if(this.minRelevance !== undefined) - params.minRelevance = this.minRelevance; - - if(this.rotationRate !== undefined) - params.rotationRate = this.rotationRate; - - if(this.rotationTime !== undefined) - params.rotationTime = this.rotationTime; - - if(this.expertSettings !== undefined) - params.expertSettings = this.expertSettings; - - return params; - } - - /** - * Get query parameters - * @return {Object} The values of query parameters (name of parameter: value of the parameter) - */ - queryParameters() { - let params = {}; - return params; - } -} - -exports.UserBasedRecommendation = UserBasedRecommendation diff --git a/package.json b/package.json index a61db6f..4612573 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "recombee-api-client", - "version": "3.2.0", + "version": "4.0.0", "description": "Node.js client (SDK) for easy use of the Recombee recommendation API", "main": "index.js", "scripts": { @@ -26,8 +26,7 @@ }, "homepage": "https://github.com/Recombee/node-api-client#readme", "dependencies": { - "request-promise": "^4.2.5", - "request": "^2.88.0", + "got": "^11.8.2", "jssha": "^2.3.0" }, "devDependencies": { diff --git a/test/add-bookmark-test.js b/test/add-bookmark-test.js index 6e681bb..21016e1 100644 --- a/test/add-bookmark-test.js +++ b/test/add-bookmark-test.js @@ -55,9 +55,12 @@ describe('AddBookmark', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -69,9 +72,12 @@ describe('AddBookmark', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -83,9 +89,12 @@ describe('AddBookmark', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -99,9 +108,12 @@ describe('AddBookmark', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-cart-addition-test.js b/test/add-cart-addition-test.js index 58a2c0f..1e68987 100644 --- a/test/add-cart-addition-test.js +++ b/test/add-cart-addition-test.js @@ -55,9 +55,12 @@ describe('AddCartAddition', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -69,9 +72,12 @@ describe('AddCartAddition', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -83,9 +89,12 @@ describe('AddCartAddition', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -99,9 +108,12 @@ describe('AddCartAddition', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-detail-view-test.js b/test/add-detail-view-test.js index 37b9f8b..0752845 100644 --- a/test/add-detail-view-test.js +++ b/test/add-detail-view-test.js @@ -55,9 +55,12 @@ describe('AddDetailView', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -69,9 +72,12 @@ describe('AddDetailView', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -83,9 +89,12 @@ describe('AddDetailView', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -99,9 +108,12 @@ describe('AddDetailView', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-group-test.js b/test/add-group-test.js index 50939b2..a4c7591 100644 --- a/test/add-group-test.js +++ b/test/add-group-test.js @@ -37,9 +37,12 @@ describe('AddGroup', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -53,9 +56,12 @@ describe('AddGroup', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-item-property-test.js b/test/add-item-property-test.js index 07c4ef3..c77bb73 100644 --- a/test/add-item-property-test.js +++ b/test/add-item-property-test.js @@ -41,9 +41,12 @@ describe('AddItemProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -57,9 +60,12 @@ describe('AddItemProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-item-test.js b/test/add-item-test.js index dd02bf4..11b63da 100644 --- a/test/add-item-test.js +++ b/test/add-item-test.js @@ -37,9 +37,12 @@ describe('AddItem', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -53,9 +56,12 @@ describe('AddItem', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-purchase-test.js b/test/add-purchase-test.js index 5d0d2be..c06936a 100644 --- a/test/add-purchase-test.js +++ b/test/add-purchase-test.js @@ -55,9 +55,12 @@ describe('AddPurchase', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -69,9 +72,12 @@ describe('AddPurchase', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -83,9 +89,12 @@ describe('AddPurchase', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -99,9 +108,12 @@ describe('AddPurchase', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-rating-test.js b/test/add-rating-test.js index 00ff490..c061743 100644 --- a/test/add-rating-test.js +++ b/test/add-rating-test.js @@ -46,9 +46,12 @@ describe('AddRating', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -60,9 +63,12 @@ describe('AddRating', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -74,9 +80,12 @@ describe('AddRating', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -88,9 +97,12 @@ describe('AddRating', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -104,9 +116,12 @@ describe('AddRating', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-search-synonym-test.js b/test/add-search-synonym-test.js index 4152dec..b995591 100644 --- a/test/add-search-synonym-test.js +++ b/test/add-search-synonym-test.js @@ -33,9 +33,12 @@ describe('AddSearchSynonym', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-series-test.js b/test/add-series-test.js index 71a35c2..3ca0432 100644 --- a/test/add-series-test.js +++ b/test/add-series-test.js @@ -37,9 +37,12 @@ describe('AddSeries', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -53,9 +56,12 @@ describe('AddSeries', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-user-property-test.js b/test/add-user-property-test.js index d1deddc..59925c1 100644 --- a/test/add-user-property-test.js +++ b/test/add-user-property-test.js @@ -41,9 +41,12 @@ describe('AddUserProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -57,9 +60,12 @@ describe('AddUserProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/add-user-test.js b/test/add-user-test.js index a236e2e..d3f7e1c 100644 --- a/test/add-user-test.js +++ b/test/add-user-test.js @@ -37,9 +37,12 @@ describe('AddUser', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -53,9 +56,12 @@ describe('AddUser', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/delete-bookmark-test.js b/test/delete-bookmark-test.js index dcfa72b..261011e 100644 --- a/test/delete-bookmark-test.js +++ b/test/delete-bookmark-test.js @@ -32,9 +32,12 @@ describe('DeleteBookmark', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-cart-addition-test.js b/test/delete-cart-addition-test.js index 10f8aba..da64cd7 100644 --- a/test/delete-cart-addition-test.js +++ b/test/delete-cart-addition-test.js @@ -32,9 +32,12 @@ describe('DeleteCartAddition', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-detail-view-test.js b/test/delete-detail-view-test.js index 558f308..fb72213 100644 --- a/test/delete-detail-view-test.js +++ b/test/delete-detail-view-test.js @@ -32,9 +32,12 @@ describe('DeleteDetailView', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-group-test.js b/test/delete-group-test.js index 9afad11..2ab610f 100644 --- a/test/delete-group-test.js +++ b/test/delete-group-test.js @@ -30,9 +30,12 @@ describe('DeleteGroup', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); @@ -45,9 +48,12 @@ describe('DeleteGroup', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -59,9 +65,12 @@ describe('DeleteGroup', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-item-property-test.js b/test/delete-item-property-test.js index f020c9c..7d93e9e 100644 --- a/test/delete-item-property-test.js +++ b/test/delete-item-property-test.js @@ -30,9 +30,12 @@ describe('DeleteItemProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); @@ -45,9 +48,12 @@ describe('DeleteItemProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -59,9 +65,12 @@ describe('DeleteItemProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-item-test.js b/test/delete-item-test.js index 36c7d62..9b8a214 100644 --- a/test/delete-item-test.js +++ b/test/delete-item-test.js @@ -30,9 +30,12 @@ describe('DeleteItem', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); @@ -45,9 +48,12 @@ describe('DeleteItem', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -59,9 +65,12 @@ describe('DeleteItem', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/user-based-recommendation-batch_test.js b/test/delete-more-items-batch_test.js similarity index 50% rename from test/user-based-recommendation-batch_test.js rename to test/delete-more-items-batch_test.js index 5de5eb5..d097723 100644 --- a/test/user-based-recommendation-batch_test.js +++ b/test/delete-more-items-batch_test.js @@ -9,32 +9,26 @@ var rqs = recombee.requests; var env = require('./set-environment.js'); -describe('UserBasedRecommendation', function(){ +describe('DeleteMoreItems', function(){ this.timeout(150000); before(function(done){ env.setEnvironment() - .then(env.setRecommEntities) .then(()=> { done(); }); }); it ('works in batch', (done) => { let requests = [ - new rqs.UserBasedRecommendation('entity_id',9), - new rqs.UserBasedRecommendation('nonexisting',9,{'cascadeCreate': true}), - new rqs.UserBasedRecommendation('nonexisting2',9,{'cascadeCreate': true,'expertSettings': {}}) + new rqs.DeleteMoreItems('\'int_property\' == 42') ]; env.client.send(new rqs.Batch(requests)) .then((responses) => { chai.equal(responses[0].code, 200); - chai.equal(responses[0].json.length, 9); - chai.equal(responses[1].code, 200); - chai.equal(responses[1].json.length, 9); - chai.equal(responses[2].code, 200); - chai.equal(responses[2].json.length, 9); + chai.equal(responses[0].json['itemIds'].length, 1); + chai.deepEqual(1, responses[0].json['count']); done(); }); }); diff --git a/test/delete-more-items-callback_test.js b/test/delete-more-items-callback_test.js new file mode 100644 index 0000000..2fc5295 --- /dev/null +++ b/test/delete-more-items-callback_test.js @@ -0,0 +1,37 @@ +/* + This file is auto-generated, do not edit +*/ + +'use strict' +var chai = require('chai').assert; +var recombee = require('./../index.js'); +var rqs = recombee.requests; + +var env = require('./set-environment.js'); + +describe('DeleteMoreItems', function(){ + this.timeout(150000); + + before(function(done){ + + env.setEnvironment() + .then(()=> { + done(); + }); + }); + + it ('deletes more items', (done) => { + let req, req2, resp; + req = new rqs.DeleteMoreItems('\'int_property\' == 42'); + env.client.send(req,((err,res) => { + if(err) { + chai.fail(); + } + else { + chai.equal(res['itemIds'].length, 1); + chai.deepEqual(1, res['count']); + done(); + } + })); + }); +}); diff --git a/test/delete-more-items-test.js b/test/delete-more-items-test.js new file mode 100644 index 0000000..7e9df0f --- /dev/null +++ b/test/delete-more-items-test.js @@ -0,0 +1,33 @@ +/* + This file is auto-generated, do not edit +*/ + +'use strict' +var chai = require('chai').assert; +var recombee = require('./../index.js'); +var rqs = recombee.requests; + +var env = require('./set-environment.js'); + +describe('DeleteMoreItems', function(){ + this.timeout(150000); + + before(function(done){ + + env.setEnvironment() + .then(()=> { + done(); + }); + }); + + it ('deletes more items', (done) => { + let req, req2, resp; + req = new rqs.DeleteMoreItems('\'int_property\' == 42'); + env.client.send(req) + .then((res) => { + chai.equal(res['itemIds'].length, 1); + chai.deepEqual(1, res['count']); + done(); + }); + }); +}); diff --git a/test/delete-purchase-test.js b/test/delete-purchase-test.js index 78722a6..2f226c9 100644 --- a/test/delete-purchase-test.js +++ b/test/delete-purchase-test.js @@ -32,9 +32,12 @@ describe('DeletePurchase', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-rating-test.js b/test/delete-rating-test.js index 28976f2..2fca97a 100644 --- a/test/delete-rating-test.js +++ b/test/delete-rating-test.js @@ -32,9 +32,12 @@ describe('DeleteRating', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-search-synonym-test.js b/test/delete-search-synonym-test.js index df391a7..c7b274c 100644 --- a/test/delete-search-synonym-test.js +++ b/test/delete-search-synonym-test.js @@ -34,9 +34,12 @@ describe('DeleteSearchSynonym', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-series-test.js b/test/delete-series-test.js index fea7a87..beb11c5 100644 --- a/test/delete-series-test.js +++ b/test/delete-series-test.js @@ -30,9 +30,12 @@ describe('DeleteSeries', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); @@ -45,9 +48,12 @@ describe('DeleteSeries', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -59,9 +65,12 @@ describe('DeleteSeries', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-user-property-test.js b/test/delete-user-property-test.js index 7acd648..98248dd 100644 --- a/test/delete-user-property-test.js +++ b/test/delete-user-property-test.js @@ -30,9 +30,12 @@ describe('DeleteUserProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); @@ -45,9 +48,12 @@ describe('DeleteUserProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -59,9 +65,12 @@ describe('DeleteUserProperty', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-user-test.js b/test/delete-user-test.js index 3fed455..b7be257 100644 --- a/test/delete-user-test.js +++ b/test/delete-user-test.js @@ -30,9 +30,12 @@ describe('DeleteUser', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); @@ -45,9 +48,12 @@ describe('DeleteUser', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -59,9 +65,12 @@ describe('DeleteUser', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/delete-view-portion-test.js b/test/delete-view-portion-test.js index ad79fdd..7f06594 100644 --- a/test/delete-view-portion-test.js +++ b/test/delete-view-portion-test.js @@ -32,9 +32,12 @@ describe('DeleteViewPortion', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/insert-to-group-test.js b/test/insert-to-group-test.js index 50833f9..f5d8977 100644 --- a/test/insert-to-group-test.js +++ b/test/insert-to-group-test.js @@ -55,9 +55,12 @@ describe('InsertToGroup', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/insert-to-series-test.js b/test/insert-to-series-test.js index f9c729a..a95f4b8 100644 --- a/test/insert-to-series-test.js +++ b/test/insert-to-series-test.js @@ -55,9 +55,12 @@ describe('InsertToSeries', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 409); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 409); + done(); + } + throw err; }); }); }); diff --git a/test/item-based-recommendation-callback_test.js b/test/item-based-recommendation-callback_test.js deleted file mode 100644 index 75f91cd..0000000 --- a/test/item-based-recommendation-callback_test.js +++ /dev/null @@ -1,65 +0,0 @@ -/* - This file is auto-generated, do not edit -*/ - -'use strict' -var chai = require('chai').assert; -var recombee = require('./../index.js'); -var rqs = recombee.requests; - -var env = require('./set-environment.js'); - -describe('ItemBasedRecommendation', function(){ - this.timeout(150000); - - before(function(done){ - - env.setEnvironment() - .then(env.setRecommEntities) - .then(()=> { - done(); - }); - }); - - it ('recommends', (done) => { - let req, req2, resp; - req = new rqs.ItemBasedRecommendation('entity_id',9); - env.client.send(req,((err,res) => { - if(err) { - chai.fail(); - } - else { - chai.equal(res.length, 9); - done(); - } - })); - }); - - it ('recommends to previously nonexisting entity with cascadeCreate', (done) => { - let req, req2, resp; - req = new rqs.ItemBasedRecommendation('nonexisting',9,{'cascadeCreate': true}); - env.client.send(req,((err,res) => { - if(err) { - chai.fail(); - } - else { - chai.equal(res.length, 9); - done(); - } - })); - }); - - it ('recommends with expert settings', (done) => { - let req, req2, resp; - req = new rqs.ItemBasedRecommendation('nonexisting2',9,{'cascadeCreate': true,'expertSettings': {}}); - env.client.send(req,((err,res) => { - if(err) { - chai.fail(); - } - else { - chai.equal(res.length, 9); - done(); - } - })); - }); -}); diff --git a/test/item-based-recommendation-test.js b/test/item-based-recommendation-test.js deleted file mode 100644 index 083c519..0000000 --- a/test/item-based-recommendation-test.js +++ /dev/null @@ -1,53 +0,0 @@ -/* - This file is auto-generated, do not edit -*/ - -'use strict' -var chai = require('chai').assert; -var recombee = require('./../index.js'); -var rqs = recombee.requests; - -var env = require('./set-environment.js'); - -describe('ItemBasedRecommendation', function(){ - this.timeout(150000); - - before(function(done){ - - env.setEnvironment() - .then(env.setRecommEntities) - .then(()=> { - done(); - }); - }); - - it ('recommends', (done) => { - let req, req2, resp; - req = new rqs.ItemBasedRecommendation('entity_id',9); - env.client.send(req) - .then((res) => { - chai.equal(res.length, 9); - done(); - }); - }); - - it ('recommends to previously nonexisting entity with cascadeCreate', (done) => { - let req, req2, resp; - req = new rqs.ItemBasedRecommendation('nonexisting',9,{'cascadeCreate': true}); - env.client.send(req) - .then((res) => { - chai.equal(res.length, 9); - done(); - }); - }); - - it ('recommends with expert settings', (done) => { - let req, req2, resp; - req = new rqs.ItemBasedRecommendation('nonexisting2',9,{'cascadeCreate': true,'expertSettings': {}}); - env.client.send(req) - .then((res) => { - chai.equal(res.length, 9); - done(); - }); - }); -}); diff --git a/test/merge-users-test.js b/test/merge-users-test.js index 2c539d1..9dcd376 100644 --- a/test/merge-users-test.js +++ b/test/merge-users-test.js @@ -41,9 +41,12 @@ describe('MergeUsers', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/remove-from-group-test.js b/test/remove-from-group-test.js index eb9b93e..b82d6fd 100644 --- a/test/remove-from-group-test.js +++ b/test/remove-from-group-test.js @@ -37,9 +37,12 @@ describe('RemoveFromGroup', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/remove-from-series-test.js b/test/remove-from-series-test.js index 553b817..c98b0a7 100644 --- a/test/remove-from-series-test.js +++ b/test/remove-from-series-test.js @@ -28,9 +28,12 @@ describe('RemoveFromSeries', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -51,9 +54,12 @@ describe('RemoveFromSeries', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/set-environment.js b/test/set-environment.js index 66eabc5..d3d5e58 100644 --- a/test/set-environment.js +++ b/test/set-environment.js @@ -4,7 +4,7 @@ var recombee = require('./../index.js'); var rqs = recombee.requests; var errs = recombee.errors; -var client = new recombee.ApiClient('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L'); +var client = new recombee.ApiClient('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L', {'region': 'eu-west'}); var _setEnvironmentData = (() => { let requests = new rqs.Batch([ @@ -37,12 +37,14 @@ var _checkDbErased = (() => { .then((resp) => { return _setEnvironmentData(); }) - .catch(errs.ResponseError, - (err) => { + .catch((err) => { + if (err instanceof errs.ResponseError && err.statusCode === 422) { // Wait until DB is erased return _delay(2000).then(() => { return _checkDbErased(); - }) + }); + } + throw err; }) }); diff --git a/test/set-item-values-test.js b/test/set-item-values-test.js index 765a0f4..da9206f 100644 --- a/test/set-item-values-test.js +++ b/test/set-item-values-test.js @@ -73,9 +73,12 @@ describe('SetItemValues', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/set-user-values-test.js b/test/set-user-values-test.js index 1c68abf..fb54318 100644 --- a/test/set-user-values-test.js +++ b/test/set-user-values-test.js @@ -73,9 +73,12 @@ describe('SetUserValues', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); }); diff --git a/test/set-view-portion-test.js b/test/set-view-portion-test.js index de06659..7f44807 100644 --- a/test/set-view-portion-test.js +++ b/test/set-view-portion-test.js @@ -46,9 +46,12 @@ describe('SetViewPortion', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -60,9 +63,12 @@ describe('SetViewPortion', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 404); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 404); + done(); + } + throw err; }); }); @@ -74,9 +80,12 @@ describe('SetViewPortion', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -88,9 +97,12 @@ describe('SetViewPortion', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); @@ -102,9 +114,12 @@ describe('SetViewPortion', function(){ chai.fail(); done(); }) - .catch(recombee.errors.ResponseError,(err) => { - chai.equal(err.statusCode, 400); - done(); + .catch((err) => { + if (err instanceof recombee.errors.ResponseError) { + chai.equal(err.statusCode, 400); + done(); + } + throw err; }); }); }); diff --git a/test/item-based-recommendation-batch_test.js b/test/update-more-items-batch_test.js similarity index 50% rename from test/item-based-recommendation-batch_test.js rename to test/update-more-items-batch_test.js index 2037770..2bfaf41 100644 --- a/test/item-based-recommendation-batch_test.js +++ b/test/update-more-items-batch_test.js @@ -9,32 +9,26 @@ var rqs = recombee.requests; var env = require('./set-environment.js'); -describe('ItemBasedRecommendation', function(){ +describe('UpdateMoreItems', function(){ this.timeout(150000); before(function(done){ env.setEnvironment() - .then(env.setRecommEntities) .then(()=> { done(); }); }); it ('works in batch', (done) => { let requests = [ - new rqs.ItemBasedRecommendation('entity_id',9), - new rqs.ItemBasedRecommendation('nonexisting',9,{'cascadeCreate': true}), - new rqs.ItemBasedRecommendation('nonexisting2',9,{'cascadeCreate': true,'expertSettings': {}}) + new rqs.UpdateMoreItems('\'int_property\' == 42',{'int_property': 77}) ]; env.client.send(new rqs.Batch(requests)) .then((responses) => { chai.equal(responses[0].code, 200); - chai.equal(responses[0].json.length, 9); - chai.equal(responses[1].code, 200); - chai.equal(responses[1].json.length, 9); - chai.equal(responses[2].code, 200); - chai.equal(responses[2].json.length, 9); + chai.equal(responses[0].json['itemIds'].length, 1); + chai.deepEqual(1, responses[0].json['count']); done(); }); }); diff --git a/test/update-more-items-callback_test.js b/test/update-more-items-callback_test.js new file mode 100644 index 0000000..c677097 --- /dev/null +++ b/test/update-more-items-callback_test.js @@ -0,0 +1,37 @@ +/* + This file is auto-generated, do not edit +*/ + +'use strict' +var chai = require('chai').assert; +var recombee = require('./../index.js'); +var rqs = recombee.requests; + +var env = require('./set-environment.js'); + +describe('UpdateMoreItems', function(){ + this.timeout(150000); + + before(function(done){ + + env.setEnvironment() + .then(()=> { + done(); + }); + }); + + it ('updates more items', (done) => { + let req, req2, resp; + req = new rqs.UpdateMoreItems('\'int_property\' == 42',{'int_property': 77}); + env.client.send(req,((err,res) => { + if(err) { + chai.fail(); + } + else { + chai.equal(res['itemIds'].length, 1); + chai.deepEqual(1, res['count']); + done(); + } + })); + }); +}); diff --git a/test/update-more-items-test.js b/test/update-more-items-test.js new file mode 100644 index 0000000..0cf488b --- /dev/null +++ b/test/update-more-items-test.js @@ -0,0 +1,33 @@ +/* + This file is auto-generated, do not edit +*/ + +'use strict' +var chai = require('chai').assert; +var recombee = require('./../index.js'); +var rqs = recombee.requests; + +var env = require('./set-environment.js'); + +describe('UpdateMoreItems', function(){ + this.timeout(150000); + + before(function(done){ + + env.setEnvironment() + .then(()=> { + done(); + }); + }); + + it ('updates more items', (done) => { + let req, req2, resp; + req = new rqs.UpdateMoreItems('\'int_property\' == 42',{'int_property': 77}); + env.client.send(req) + .then((res) => { + chai.equal(res['itemIds'].length, 1); + chai.deepEqual(1, res['count']); + done(); + }); + }); +}); diff --git a/test/user-based-recommendation-callback_test.js b/test/user-based-recommendation-callback_test.js deleted file mode 100644 index d72747f..0000000 --- a/test/user-based-recommendation-callback_test.js +++ /dev/null @@ -1,65 +0,0 @@ -/* - This file is auto-generated, do not edit -*/ - -'use strict' -var chai = require('chai').assert; -var recombee = require('./../index.js'); -var rqs = recombee.requests; - -var env = require('./set-environment.js'); - -describe('UserBasedRecommendation', function(){ - this.timeout(150000); - - before(function(done){ - - env.setEnvironment() - .then(env.setRecommEntities) - .then(()=> { - done(); - }); - }); - - it ('recommends', (done) => { - let req, req2, resp; - req = new rqs.UserBasedRecommendation('entity_id',9); - env.client.send(req,((err,res) => { - if(err) { - chai.fail(); - } - else { - chai.equal(res.length, 9); - done(); - } - })); - }); - - it ('recommends to previously nonexisting entity with cascadeCreate', (done) => { - let req, req2, resp; - req = new rqs.UserBasedRecommendation('nonexisting',9,{'cascadeCreate': true}); - env.client.send(req,((err,res) => { - if(err) { - chai.fail(); - } - else { - chai.equal(res.length, 9); - done(); - } - })); - }); - - it ('recommends with expert settings', (done) => { - let req, req2, resp; - req = new rqs.UserBasedRecommendation('nonexisting2',9,{'cascadeCreate': true,'expertSettings': {}}); - env.client.send(req,((err,res) => { - if(err) { - chai.fail(); - } - else { - chai.equal(res.length, 9); - done(); - } - })); - }); -}); diff --git a/test/user-based-recommendation-test.js b/test/user-based-recommendation-test.js deleted file mode 100644 index e379085..0000000 --- a/test/user-based-recommendation-test.js +++ /dev/null @@ -1,53 +0,0 @@ -/* - This file is auto-generated, do not edit -*/ - -'use strict' -var chai = require('chai').assert; -var recombee = require('./../index.js'); -var rqs = recombee.requests; - -var env = require('./set-environment.js'); - -describe('UserBasedRecommendation', function(){ - this.timeout(150000); - - before(function(done){ - - env.setEnvironment() - .then(env.setRecommEntities) - .then(()=> { - done(); - }); - }); - - it ('recommends', (done) => { - let req, req2, resp; - req = new rqs.UserBasedRecommendation('entity_id',9); - env.client.send(req) - .then((res) => { - chai.equal(res.length, 9); - done(); - }); - }); - - it ('recommends to previously nonexisting entity with cascadeCreate', (done) => { - let req, req2, resp; - req = new rqs.UserBasedRecommendation('nonexisting',9,{'cascadeCreate': true}); - env.client.send(req) - .then((res) => { - chai.equal(res.length, 9); - done(); - }); - }); - - it ('recommends with expert settings', (done) => { - let req, req2, resp; - req = new rqs.UserBasedRecommendation('nonexisting2',9,{'cascadeCreate': true,'expertSettings': {}}); - env.client.send(req) - .then((res) => { - chai.equal(res.length, 9); - done(); - }); - }); -});