├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .snyk ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── package-lock.json ├── package.json ├── src ├── errors │ ├── index.js │ ├── tinder-not-authorized-error.js │ └── tinder-out-of-likes-error.js ├── index.js └── tinder-wrapper.js └── test ├── index.js ├── mocha.js ├── mocha.opts └── tinder-wrapper.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "env", 5 | { 6 | "targets": { 7 | "node": 6 8 | } 9 | } 10 | ] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | coverage 4 | lib 5 | test 6 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-hfreire" 3 | } 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: hfreire 2 | custom: 'https://paypal.me/hfreire' 3 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "04:00" 8 | open-pull-requests-limit: 10 9 | commit-message: 10 | prefix: fix 11 | prefix-development: chore 12 | include: scope 13 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [push] 4 | 5 | jobs: 6 | test: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | env: 11 | CI: true 12 | VERSION_COMMIT: ${{ github.sha }} 13 | 14 | steps: 15 | - uses: actions/checkout@v1 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: 12.14 19 | - name: Install NPM dependencies 20 | run: npm ci 21 | - name: Build source code 22 | run: npm run build --if-present 23 | - name: Test source code 24 | run: npm test 25 | - name: Submit coveralls test coverage report 26 | uses: coverallsapp/github-action@v1.1.2 27 | with: 28 | github-token: ${{ secrets.GITHUB_TOKEN }} 29 | - name: Check if release should be created 30 | run: npm run semantic-release 31 | env: 32 | GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }} 33 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | coverage 4 | node_modules 5 | lib 6 | *.log 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .dependabot/ 2 | .github/ 3 | .idea/ 4 | coverage/ 5 | src/ 6 | test/ 7 | .babelrc 8 | .editorconfig 9 | .eslint* 10 | .gitignore 11 | .snyk 12 | -------------------------------------------------------------------------------- /.snyk: -------------------------------------------------------------------------------- 1 | # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. 2 | version: v1.12.0 3 | ignore: {} 4 | # patches apply the minimum changes required to fix a vulnerability 5 | patch: 6 | 'npm:lodash:20180130': 7 | - socks5-http-client > npm > cli-table2 > lodash: 8 | patched: '2018-07-03T07:38:13.918Z' 9 | - socks5-http-client > npm > npm-audit-report > cli-table2 > lodash: 10 | patched: '2018-07-03T07:38:13.918Z' 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | This GitHub repo follows the [GitHub Flow](https://guides.github.com/introduction/flow/) git workflow. In essence, you contribute by making changes in your fork and then generating a pull request of those changes to be merged with the upstream. 3 | 4 | ### How to fork this repo 5 | You can read more about forking a GitHub repo [here](https://help.github.com/articles/fork-a-repo). Once you've forked this repo, you're now ready to clone the repo in your computer and start hacking and tinkering with its code. 6 | 7 | Clone the GitHub repo 8 | ``` 9 | git clone https://github.com/my-github-username/tinder-wrapper 10 | ``` 11 | 12 | Change current directory 13 | ``` 14 | cd tinder-wrapper 15 | ``` 16 | 17 | Install NPM dependencies 18 | ``` 19 | npm install 20 | ``` 21 | 22 | ### How to keep your fork synced 23 | It's generally a good idea to pull upstream changes and merge them with your fork regularly. [Greenkeeper app](https://github.com/marketplace/greenkeeper) is installed in this GitHub project, it will automatically update dependencies and merge them with upstream if possible. 24 | 25 | Add remote upstream 26 | ``` 27 | git remote add upstream https://github.com/hfreire/tinder-wrapper 28 | ``` 29 | 30 | Fetch from remote upstream master branch 31 | ``` 32 | git fetch upstream master 33 | ``` 34 | 35 | Merge upstream with your local master branch 36 | ``` 37 | git merge upstream/master 38 | ``` 39 | 40 | Install, update and prune removed NPM dependencies 41 | ``` 42 | npm install && npm prune 43 | ``` 44 | 45 | ### How to know what to contribute 46 | The list of outstanding feature requests and bugs can be found in the [GitHub issue tracker](https://github.com/hfreire/tinder-wrapper/issues) of this repo. Please, feel free to propose features or report bugs that are not there. 47 | 48 | ### How to style the code 49 | With the exception rules from [eslint-config-hfreire](https://github.com/hfreire/eslint-config-hfreire), this repo follows the [JavaScript Standard Style](https://standardjs.com/) rules. 50 | 51 | Run the NPM script that will verify the code for style guide violations 52 | ``` 53 | npm run lint 54 | ``` 55 | 56 | ### How to test the code locally 57 | You are encouraged to write automated test cases of your changes. This repo uses [Mocha](https://mochajs.org/) test framework with [testdouble.js](https://github.com/testdouble/testdouble.js) for faking, mocking and stubbing and [Chai](http://chaijs.com) for assertion. 58 | 59 | Run the NPM script that will verify failing test cases and report automated test coverage 60 | ``` 61 | npm run coverage 62 | ``` 63 | 64 | ### How to commit changes 65 | This repo follows the [AngularJS git commit guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits). 66 | 67 | Run the NPM script that will commit changes through an interactive menu 68 | ``` 69 | npm run commit 70 | ``` 71 | 72 | ### How to generate a pull request 73 | You can read more about creating a GitHub pull request from a fork [here](https://help.github.com/articles/creating-a-pull-request-from-a-fork). 74 | 75 | ### How to get your pull request accepted 76 | Every pull request is welcomed, but it's important, as well, to have maintainable code and avoid regression bugs while adding features or fixing other bugs. 77 | 78 | Once you generate a pull request, GitHub and third-party apps will verify if the changes are suitable to be merged with upstream. [GitHub Actions CI workflow](https://github.com/hfreire/tinder-wrapper/actions?workflow=ci) will verify your changes for style guide violations and failing test cases, while, [Coveralls](https://coveralls.io/github/hfreire/request-on-steroids) will verify the coverage of the automated test cases against the code. 79 | 80 | You are encouraged to verify your changes by testing the code locally. 81 | 82 | Run the NPM script that will verify the code for style guide violations, failing test cases and report automated test coverage 83 | ``` 84 | npm test 85 | ``` 86 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 [Hugo Freire](mailto:hugo@exec.sh) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A :revolving_hearts: Tinder :package: wrapper library 2 | 3 | [![](https://github.com/hfreire/tinder-wrapper/workflows/ci/badge.svg)](https://github.com/hfreire/tinder-wrapper/actions?workflow=ci) 4 | [![Coverage Status](https://coveralls.io/repos/github/hfreire/tinder-wrapper/badge.svg?branch=master)](https://coveralls.io/github/hfreire/tinder-wrapper?branch=master) 5 | [![Known Vulnerabilities](https://snyk.io/test/github/hfreire/tinder-wrapper/badge.svg)](https://snyk.io/test/github/hfreire/tinder-wrapper) 6 | [![](https://img.shields.io/github/release/hfreire/tinder-wrapper.svg)](https://github.com/hfreire/tinder-wrapper/releases) 7 | [![Version](https://img.shields.io/npm/v/tinder-wrapper.svg)](https://www.npmjs.com/package/tinder-wrapper) 8 | [![Downloads](https://img.shields.io/npm/dt/tinder-wrapper.svg)](https://www.npmjs.com/package/tinder-wrapper) 9 | 10 | > A Tinder wrapper library. 11 | 12 | ### Features 13 | * Uses [Request on Steroids](https://github.com/hfreire/request-on-steroids) to rate limit, retry and circuit break outgoing HTTP requests :white_check_mark: 14 | * Supports [Bluebird](https://github.com/petkaantonov/bluebird) :bird: promises :white_check_mark: 15 | 16 | ### How to install 17 | ``` 18 | npm install tinder-wrapper 19 | ``` 20 | 21 | ### How to use 22 | 23 | #### Use it in your app 24 | Authorize Facebook account and get recommendations 25 | ```javascript 26 | const TinderWrapper = require('tinder-wrapper') 27 | 28 | const tinder = new TinderWrapper() 29 | const facebookAccessToken = 'my-facebook-access-token' 30 | const facebookUserId = 'my-facebook-id' 31 | 32 | tinder.authorize(facebookAccessToken, facebookUserId) 33 | .then(() => tinder.getRecommendations()) 34 | .then(({ results }) => console.log(results)) 35 | ``` 36 | 37 | ### How to contribute 38 | You can contribute either with code (e.g., new features, bug fixes and documentation) or by [donating 5 EUR](https://paypal.me/hfreire/5). You can read the [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute with code. 39 | 40 | All donation proceedings will go to the [Sverige för UNHCR](https://sverigeforunhcr.se), a swedish partner of the [UNHCR - The UN Refugee Agency](http://www.unhcr.org), a global organisation dedicated to saving lives, protecting rights and building a better future for refugees, forcibly displaced communities and stateless people. 41 | 42 | ### Used by 43 | * [get-me-a-date](https://github.com/hfreire/get-me-a-date) - :heart_eyes: Help me get a :cupid: date tonight :first_quarter_moon_with_face: 44 | 45 | ### License 46 | Read the [license](./LICENSE.md) for permissions and limitations. 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tinder-wrapper", 3 | "description": "A Tinder wrapper library", 4 | "version": "0.0.0", 5 | "engines": { 6 | "node": ">= 6.0.0" 7 | }, 8 | "main": "lib/index.js", 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/hfreire/tinder-wrapper.git" 12 | }, 13 | "author": "Hugo Freire ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/hfreire/tinder-wrapper/issues" 17 | }, 18 | "homepage": "https://github.com/hfreire/tinder-wrapper#readme", 19 | "dependencies": { 20 | "bluebird": "3.7.2", 21 | "lodash": "4.17.21", 22 | "request-on-steroids": "1.1.110" 23 | }, 24 | "devDependencies": { 25 | "babel-cli": "6.26.0", 26 | "babel-preset-env": "1.7.0", 27 | "chai": "4.3.4", 28 | "chai-as-promised": "7.1.1", 29 | "eslint": "6.8.0", 30 | "eslint-config-hfreire": "2.0.7", 31 | "eslint-plugin-import": "2.25.2", 32 | "eslint-plugin-jest": "25.2.2", 33 | "eslint-plugin-json": "3.1.0", 34 | "eslint-plugin-mocha": "6.3.0", 35 | "eslint-plugin-node": "11.1.0", 36 | "eslint-plugin-promise": "4.3.1", 37 | "eslint-plugin-standard": "5.0.0", 38 | "eslint-plugin-unicorn": "19.0.1", 39 | "istanbul": "0.4.5", 40 | "mocha": "9.1.3", 41 | "pre-git": "3.17.1", 42 | "semantic-release": "17.4.7", 43 | "snyk": "1.749.0", 44 | "testdouble": "3.16.3" 45 | }, 46 | "config": { 47 | "pre-git": { 48 | "commit-msg": "conventional", 49 | "allow-untracked-files": true 50 | } 51 | }, 52 | "snyk": true, 53 | "scripts": { 54 | "eslint": "node_modules/.bin/eslint --ext .json --ext .js .", 55 | "istanbul": "node_modules/.bin/istanbul cover --include-all-sources --root src --print detail ./node_modules/mocha/bin/_mocha -- --recursive test", 56 | "snyk:test": "./node_modules/.bin/snyk test", 57 | "snyk:protect": "./node_modules/.bin/snyk protect", 58 | "babel": "mkdir -p lib && ./node_modules/.bin/babel src/ -d lib", 59 | "semantic-release": "./node_modules/.bin/semantic-release", 60 | "clean": "rm -rf lib coverage", 61 | "lint": "npm run eslint", 62 | "prepare": "npm run snyk:protect", 63 | "test": "npm run clean && npm run lint && npm run istanbul", 64 | "compile": "npm run clean && npm run babel", 65 | "commit": "./node_modules/.bin/commit-wizard", 66 | "prepublish": "npm run compile" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/errors/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Hugo Freire . 3 | * 4 | * This source code is licensed under the license found in the 5 | * LICENSE.md file in the root directory of this source tree. 6 | */ 7 | 8 | module.exports = { 9 | TinderNotAuthorizedError: require('./tinder-not-authorized-error'), 10 | TinderOutOfLikesError: require('./tinder-out-of-likes-error') 11 | } 12 | -------------------------------------------------------------------------------- /src/errors/tinder-not-authorized-error.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Hugo Freire . 3 | * 4 | * This source code is licensed under the license found in the 5 | * LICENSE.md file in the root directory of this source tree. 6 | */ 7 | 8 | class TinderNotAuthorizedError extends Error { 9 | constructor (message) { 10 | super(message) 11 | 12 | this.name = this.constructor.name 13 | 14 | if (typeof Error.captureStackTrace === 'function') { 15 | Error.captureStackTrace(this, this.constructor) 16 | } else { 17 | this.stack = (new Error(message)).stack 18 | } 19 | } 20 | } 21 | 22 | module.exports = TinderNotAuthorizedError 23 | -------------------------------------------------------------------------------- /src/errors/tinder-out-of-likes-error.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Hugo Freire . 3 | * 4 | * This source code is licensed under the license found in the 5 | * LICENSE.md file in the root directory of this source tree. 6 | */ 7 | 8 | class TinderOutOfLikesError extends Error { 9 | constructor (message) { 10 | super(message) 11 | 12 | this.name = this.constructor.name 13 | 14 | if (typeof Error.captureStackTrace === 'function') { 15 | Error.captureStackTrace(this, this.constructor) 16 | } else { 17 | this.stack = (new Error(message)).stack 18 | } 19 | } 20 | } 21 | 22 | module.exports = TinderOutOfLikesError 23 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Hugo Freire . 3 | * 4 | * This source code is licensed under the license found in the 5 | * LICENSE.md file in the root directory of this source tree. 6 | */ 7 | 8 | module.exports = { 9 | TinderWrapper: require('./tinder-wrapper'), 10 | TinderNotAuthorizedError: require('./errors').TinderNotAuthorizedError, 11 | TinderOutOfLikesError: require('./errors').TinderOutOfLikesError 12 | } 13 | -------------------------------------------------------------------------------- /src/tinder-wrapper.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Hugo Freire . 3 | * 4 | * This source code is licensed under the license found in the 5 | * LICENSE.md file in the root directory of this source tree. 6 | */ 7 | 8 | const BASE_URL = 'https://api.gotinder.com' 9 | 10 | const _ = require('lodash') 11 | const Promise = require('bluebird') 12 | 13 | const { TinderNotAuthorizedError, TinderOutOfLikesError } = require('./errors') 14 | 15 | const Request = require('request-on-steroids') 16 | 17 | const responseHandler = ({ statusCode, statusMessage, body }) => { 18 | if (statusCode >= 300) { 19 | switch (statusCode) { 20 | case 401: 21 | throw new TinderNotAuthorizedError() 22 | default: 23 | throw new Error(`${statusCode} ${statusMessage}`) 24 | } 25 | } 26 | 27 | if (body && body.status && body.status !== 200) { 28 | throw new Error(`${body.status} ${body.error}`) 29 | } 30 | 31 | return body 32 | } 33 | 34 | const defaultOptions = { 35 | 'request-on-steroids': { 36 | request: { 37 | headers: { 38 | 'User-Agent': 'Tinder Android Version 4.5.5', 39 | 'os_version': '23', 40 | 'platform': 'android', 41 | 'app-version': '854', 42 | 'Accept-Language': 'en' 43 | } 44 | }, 45 | perseverance: { 46 | retry: { 47 | max_tries: 2, 48 | interval: 1000, 49 | timeout: 16000, 50 | throw_original: true, 51 | predicate: (error) => !(error instanceof TinderNotAuthorizedError) 52 | }, 53 | breaker: { timeout: 12000, threshold: 80, circuitDuration: 3 * 60 * 60 * 1000 } 54 | } 55 | } 56 | } 57 | 58 | class TinderWrapper { 59 | constructor (options = {}) { 60 | this._options = _.defaultsDeep({}, options, defaultOptions) 61 | 62 | this._request = new Request(_.get(this._options, 'request-on-steroids')) 63 | } 64 | 65 | set authToken (authToken) { 66 | this._authToken = authToken 67 | } 68 | 69 | get authToken () { 70 | return this._authToken 71 | } 72 | 73 | get circuitBreaker () { 74 | return this._request.circuitBreaker 75 | } 76 | 77 | authorize (facebookAccessToken, facebookUserId) { 78 | return Promise.try(() => { 79 | if (!facebookAccessToken || !facebookUserId) { 80 | throw new Error('invalid arguments') 81 | } 82 | }) 83 | .then(() => { 84 | const options = { 85 | url: `${BASE_URL}/auth`, 86 | body: { 87 | facebook_token: facebookAccessToken, 88 | facebook_id: facebookUserId, 89 | locale: 'en' 90 | }, 91 | json: true 92 | } 93 | 94 | return this._request.post(options, responseHandler) 95 | .then((data) => { 96 | this._authToken = data.token 97 | 98 | return data 99 | }) 100 | }) 101 | } 102 | 103 | getRecommendations () { 104 | return Promise.try(() => { 105 | if (!this._authToken) { 106 | throw new TinderNotAuthorizedError() 107 | } 108 | }) 109 | .then(() => { 110 | const options = { 111 | url: `${BASE_URL}/user/recs`, 112 | headers: { 113 | 'X-Auth-Token': this._authToken 114 | }, 115 | json: true 116 | } 117 | 118 | return this._request.get(options, responseHandler) 119 | }) 120 | } 121 | 122 | getAccount () { 123 | return Promise.try(() => { 124 | if (!this._authToken) { 125 | throw new TinderNotAuthorizedError() 126 | } 127 | }) 128 | .then(() => { 129 | const options = { 130 | url: `${BASE_URL}/meta`, 131 | headers: { 132 | 'X-Auth-Token': this._authToken 133 | }, 134 | json: true 135 | } 136 | 137 | return this._request.get(options, responseHandler) 138 | }) 139 | } 140 | 141 | getUser (userId) { 142 | return Promise.try(() => { 143 | if (!userId) { 144 | throw new Error('invalid arguments') 145 | } 146 | 147 | if (!this._authToken) { 148 | throw new TinderNotAuthorizedError() 149 | } 150 | }) 151 | .then(() => { 152 | const options = { 153 | url: `${BASE_URL}/user/${userId}`, 154 | headers: { 155 | 'X-Auth-Token': this._authToken 156 | }, 157 | json: true 158 | } 159 | 160 | return this._request.get(options, responseHandler) 161 | }) 162 | } 163 | 164 | getUpdates (lastActivityDate = '') { 165 | return Promise.try(() => { 166 | if (!(lastActivityDate instanceof Date) && !(lastActivityDate instanceof String || lastActivityDate === '')) { 167 | throw new Error('invalid arguments') 168 | } 169 | 170 | if (!this._authToken) { 171 | throw new TinderNotAuthorizedError() 172 | } 173 | }) 174 | .then(() => { 175 | let _lastActivityDate = lastActivityDate 176 | if (lastActivityDate instanceof Date) { 177 | _lastActivityDate = lastActivityDate.toISOString() 178 | } 179 | 180 | const options = { 181 | url: `${BASE_URL}/updates`, 182 | headers: { 183 | 'X-Auth-Token': this._authToken 184 | }, 185 | body: { 186 | last_activity_date: _lastActivityDate 187 | }, 188 | json: true 189 | } 190 | 191 | return this._request.post(options, responseHandler) 192 | }) 193 | } 194 | 195 | sendMessage (matchId, message) { 196 | return Promise.try(() => { 197 | if (!matchId || !message) { 198 | throw new Error('invalid arguments') 199 | } 200 | 201 | if (!this._authToken) { 202 | throw new TinderNotAuthorizedError() 203 | } 204 | }) 205 | .then(() => { 206 | const options = { 207 | url: `${BASE_URL}/user/matches/${matchId}`, 208 | headers: { 209 | 'X-Auth-Token': this._authToken 210 | }, 211 | body: { message }, 212 | json: true 213 | } 214 | 215 | return this._request.post(options, responseHandler) 216 | }) 217 | } 218 | 219 | like (userId, photoId, contentHash, sNumber) { 220 | return Promise.try(() => { 221 | if (!userId) { 222 | throw new Error('invalid arguments') 223 | } 224 | 225 | if (!this._authToken) { 226 | throw new TinderNotAuthorizedError() 227 | } 228 | }) 229 | .then(() => { 230 | const options = { 231 | url: `${BASE_URL}/like/${userId}?photoId=${photoId}&content_hash=${contentHash}&s_number=${sNumber}`, 232 | headers: { 233 | 'X-Auth-Token': this._authToken 234 | }, 235 | json: true 236 | } 237 | 238 | return this._request.get(options, responseHandler) 239 | .then((data) => { 240 | if (data && !data.likes_remaining) { 241 | throw new TinderOutOfLikesError() 242 | } 243 | 244 | return data 245 | }) 246 | }) 247 | } 248 | 249 | pass (userId) { 250 | return Promise.try(() => { 251 | if (!userId) { 252 | throw new Error('invalid arguments') 253 | } 254 | 255 | if (!this._authToken) { 256 | throw new TinderNotAuthorizedError() 257 | } 258 | }) 259 | .then(() => { 260 | const options = { 261 | url: `${BASE_URL}/pass/${userId}`, 262 | headers: { 263 | 'X-Auth-Token': this._authToken 264 | }, 265 | json: true 266 | } 267 | 268 | return this._request.get(options, responseHandler) 269 | }) 270 | } 271 | } 272 | 273 | module.exports = TinderWrapper 274 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Hugo Freire . 3 | * 4 | * This source code is licensed under the license found in the 5 | * LICENSE.md file in the root directory of this source tree. 6 | */ 7 | 8 | describe('Module', () => { 9 | let subject 10 | let TinderWrapper 11 | let TinderNotAuthorizedError 12 | let TinderOutOfLikesError 13 | 14 | before(() => { 15 | TinderWrapper = td.object() 16 | 17 | TinderNotAuthorizedError = td.object() 18 | 19 | TinderOutOfLikesError = td.object() 20 | }) 21 | 22 | afterEach(() => td.reset()) 23 | 24 | describe('when loading', () => { 25 | beforeEach(() => { 26 | td.replace('../src/tinder-wrapper', TinderWrapper) 27 | 28 | td.replace('../src/errors', { TinderNotAuthorizedError, TinderOutOfLikesError }) 29 | 30 | subject = require('../src/index') 31 | }) 32 | 33 | it('should export tinder wrapper', () => { 34 | subject.should.have.property('TinderWrapper', TinderWrapper) 35 | }) 36 | 37 | it('should export tinder not authorized error', () => { 38 | subject.should.have.property('TinderNotAuthorizedError', TinderNotAuthorizedError) 39 | }) 40 | 41 | it('should export tinder out of likes error', () => { 42 | subject.should.have.property('TinderOutOfLikesError', TinderOutOfLikesError) 43 | }) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /test/mocha.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Hugo Freire . 3 | * 4 | * This source code is licensed under the license found in the 5 | * LICENSE.md file in the root directory of this source tree. 6 | */ 7 | 8 | const Promise = require('bluebird') 9 | 10 | const chai = require('chai') 11 | chai.use(require('chai-as-promised')) 12 | chai.config.includeStack = true 13 | 14 | const td = require('testdouble') 15 | td.config({ 16 | promiseConstructor: Promise, 17 | ignoreWarnings: true 18 | }) 19 | 20 | global.should = chai.should() 21 | global.td = td 22 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ./test/mocha 2 | -------------------------------------------------------------------------------- /test/tinder-wrapper.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Hugo Freire . 3 | * 4 | * This source code is licensed under the license found in the 5 | * LICENSE.md file in the root directory of this source tree. 6 | */ 7 | 8 | /* eslint-disable promise/no-callback-in-promise */ 9 | 10 | const { TinderNotAuthorizedError, TinderOutOfLikesError } = require('../src/errors') 11 | 12 | describe('Tinder Wrapper', () => { 13 | let subject 14 | let Request 15 | 16 | before(() => { 17 | Request = td.constructor([ 'get', 'post' ]) 18 | }) 19 | 20 | afterEach(() => td.reset()) 21 | 22 | describe('when constructing', () => { 23 | beforeEach(() => { 24 | td.replace('request-on-steroids', Request) 25 | 26 | const TinderWrapper = require('../src/tinder-wrapper') 27 | subject = new TinderWrapper() 28 | }) 29 | 30 | it('should set default request headers', () => { 31 | const captor = td.matchers.captor() 32 | 33 | td.verify(new Request(captor.capture())) 34 | 35 | const options = captor.value 36 | options.should.have.nested.property('request.headers.User-Agent', 'Tinder Android Version 4.5.5') 37 | options.should.have.nested.property('request.headers.os_version', '23') 38 | options.should.have.nested.property('request.headers.platform', 'android') 39 | options.should.have.nested.property('request.headers.app-version', '854') 40 | options.should.have.nested.property('request.headers.Accept-Language', 'en') 41 | }) 42 | }) 43 | 44 | describe('when constructing and loading request-on-steroids', () => { 45 | beforeEach(() => { 46 | const TinderWrapper = require('../src/tinder-wrapper') 47 | subject = new TinderWrapper() 48 | }) 49 | 50 | it('should create a request with get function', () => { 51 | subject._request.should.have.property('get') 52 | subject._request.get.should.be.instanceOf(Function) 53 | }) 54 | 55 | it('should create a request with post function', () => { 56 | subject._request.should.have.property('post') 57 | subject._request.get.should.be.instanceOf(Function) 58 | }) 59 | }) 60 | 61 | describe('when authorizing', () => { 62 | const facebookAccessToken = 'my-facebook-access-token' 63 | const facebookUserId = 'my-facebook-user-id' 64 | const statusCode = 200 65 | const token = 'my-token' 66 | const body = { token } 67 | const response = { statusCode, body } 68 | 69 | beforeEach(() => { 70 | td.when(Request.prototype.post(td.matchers.anything(), td.callback(response))).thenResolve(body) 71 | td.replace('request-on-steroids', Request) 72 | 73 | const TinderWrapper = require('../src/tinder-wrapper') 74 | subject = new TinderWrapper() 75 | 76 | return subject.authorize(facebookAccessToken, facebookUserId) 77 | }) 78 | 79 | it('should do a post request to https://api.gotinder.com/auth', () => { 80 | const captor = td.matchers.captor() 81 | 82 | td.verify(Request.prototype.post(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 83 | 84 | const options = captor.value 85 | options.should.have.property('url', 'https://api.gotinder.com/auth') 86 | }) 87 | 88 | it('should do a post request with body', () => { 89 | const captor = td.matchers.captor() 90 | 91 | td.verify(Request.prototype.post(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 92 | 93 | const options = captor.value 94 | options.should.have.nested.property('body.facebook_token', facebookAccessToken) 95 | options.should.have.nested.property('body.facebook_id', facebookUserId) 96 | options.should.have.nested.property('body.locale', 'en') 97 | }) 98 | 99 | it('should set authentication token', () => { 100 | subject.authToken.should.be.equal(token) 101 | }) 102 | }) 103 | 104 | describe('when authorizing with invalid facebook access token and user id', () => { 105 | const facebookAccessToken = undefined 106 | const facebookUserId = undefined 107 | 108 | beforeEach(() => { 109 | const TinderWrapper = require('../src/tinder-wrapper') 110 | subject = new TinderWrapper() 111 | }) 112 | 113 | it('should reject with invalid arguments error', (done) => { 114 | subject.authorize(facebookAccessToken, facebookUserId) 115 | .catch((error) => { 116 | error.should.be.instanceOf(Error) 117 | error.message.should.be.equal('invalid arguments') 118 | 119 | done() 120 | }) 121 | }) 122 | }) 123 | 124 | describe('when getting recommendations', () => { 125 | const statusCode = 200 126 | const body = {} 127 | const response = { statusCode, body } 128 | const authToken = 'my-access-token' 129 | 130 | beforeEach(() => { 131 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve(body) 132 | td.replace('request-on-steroids', Request) 133 | 134 | const TinderWrapper = require('../src/tinder-wrapper') 135 | subject = new TinderWrapper() 136 | subject.authToken = authToken 137 | }) 138 | 139 | it('should do a get request to https://api.gotinder.com/user/recs', () => { 140 | return subject.getRecommendations() 141 | .then(() => { 142 | const captor = td.matchers.captor() 143 | 144 | td.verify(Request.prototype.get(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 145 | 146 | const options = captor.value 147 | options.should.have.property('url', 'https://api.gotinder.com/user/recs') 148 | }) 149 | }) 150 | 151 | it('should resolve with response body as data', () => { 152 | return subject.getRecommendations() 153 | .then((data) => { 154 | data.should.be.equal(body) 155 | }) 156 | }) 157 | }) 158 | 159 | describe('when getting recommendations and not authorized', () => { 160 | const statusCode = 401 161 | const response = { statusCode } 162 | const authToken = 'my-access-token' 163 | 164 | beforeEach(() => { 165 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve() 166 | td.replace('request-on-steroids', Request) 167 | 168 | const TinderWrapper = require('../src/tinder-wrapper') 169 | subject = new TinderWrapper() 170 | subject.authToken = authToken 171 | }) 172 | 173 | it('should reject with tinder not authorized error', (done) => { 174 | subject.getRecommendations() 175 | .catch((error) => { 176 | error.should.be.instanceOf(TinderNotAuthorizedError) 177 | 178 | done() 179 | }) 180 | }) 181 | }) 182 | 183 | describe('when getting recommendations without an access token', () => { 184 | beforeEach(() => { 185 | td.replace('request-on-steroids', Request) 186 | 187 | const TinderWrapper = require('../src/tinder-wrapper') 188 | subject = new TinderWrapper() 189 | }) 190 | 191 | it('should reject with tinder not authorized error', (done) => { 192 | subject.getRecommendations() 193 | .catch((error) => { 194 | error.should.be.instanceOf(TinderNotAuthorizedError) 195 | 196 | done() 197 | }) 198 | }) 199 | }) 200 | 201 | describe('when getting account', () => { 202 | const statusCode = 200 203 | const body = {} 204 | const response = { statusCode, body } 205 | const authToken = 'my-access-token' 206 | 207 | beforeEach(() => { 208 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve(body) 209 | td.replace('request-on-steroids', Request) 210 | 211 | const TinderWrapper = require('../src/tinder-wrapper') 212 | subject = new TinderWrapper() 213 | subject.authToken = authToken 214 | }) 215 | 216 | it('should do a get request to https://api.gotinder.com/meta', () => { 217 | return subject.getAccount() 218 | .then(() => { 219 | const captor = td.matchers.captor() 220 | 221 | td.verify(Request.prototype.get(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 222 | 223 | const options = captor.value 224 | options.should.have.property('url', 'https://api.gotinder.com/meta') 225 | }) 226 | }) 227 | 228 | it('should resolve with response body as data', () => { 229 | return subject.getAccount() 230 | .then((data) => { 231 | data.should.be.equal(body) 232 | }) 233 | }) 234 | }) 235 | 236 | describe('when getting account and not authorized', () => { 237 | const statusCode = 401 238 | const response = { statusCode } 239 | const authToken = 'my-access-token' 240 | 241 | beforeEach(() => { 242 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve() 243 | td.replace('request-on-steroids', Request) 244 | 245 | const TinderWrapper = require('../src/tinder-wrapper') 246 | subject = new TinderWrapper() 247 | subject.authToken = authToken 248 | }) 249 | 250 | it('should reject with tinder not authorized error', (done) => { 251 | subject.getAccount() 252 | .catch((error) => { 253 | error.should.be.instanceOf(TinderNotAuthorizedError) 254 | 255 | done() 256 | }) 257 | }) 258 | }) 259 | 260 | describe('when getting account without an access token', () => { 261 | beforeEach(() => { 262 | td.replace('request-on-steroids', Request) 263 | 264 | const TinderWrapper = require('../src/tinder-wrapper') 265 | subject = new TinderWrapper() 266 | }) 267 | 268 | it('should reject with tinder not authorized error', (done) => { 269 | subject.getAccount() 270 | .catch((error) => { 271 | error.should.be.instanceOf(TinderNotAuthorizedError) 272 | 273 | done() 274 | }) 275 | }) 276 | }) 277 | 278 | describe('when getting user', () => { 279 | const userId = 'my-user-id' 280 | const statusCode = 200 281 | const body = {} 282 | const response = { statusCode, body } 283 | const authToken = 'my-access-token' 284 | 285 | beforeEach(() => { 286 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve(body) 287 | td.replace('request-on-steroids', Request) 288 | 289 | const TinderWrapper = require('../src/tinder-wrapper') 290 | subject = new TinderWrapper() 291 | subject.authToken = authToken 292 | }) 293 | 294 | it('should do a get request to https://api.gotinder.com/user/my-user-id', () => { 295 | return subject.getUser(userId) 296 | .then(() => { 297 | const captor = td.matchers.captor() 298 | 299 | td.verify(Request.prototype.get(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 300 | 301 | const options = captor.value 302 | options.should.have.property('url', 'https://api.gotinder.com/user/my-user-id') 303 | }) 304 | }) 305 | 306 | it('should resolve with response body as data', () => { 307 | return subject.getUser(userId) 308 | .then((data) => { 309 | data.should.be.equal(body) 310 | }) 311 | }) 312 | }) 313 | 314 | describe('when getting user and not authorized', () => { 315 | const statusCode = 401 316 | const response = { statusCode } 317 | const authToken = 'my-access-token' 318 | const userId = 'my-user-id' 319 | 320 | beforeEach(() => { 321 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve() 322 | td.replace('request-on-steroids', Request) 323 | 324 | const TinderWrapper = require('../src/tinder-wrapper') 325 | subject = new TinderWrapper() 326 | subject.authToken = authToken 327 | }) 328 | 329 | it('should reject with tinder not authorized error', (done) => { 330 | subject.getUser(userId) 331 | .catch((error) => { 332 | error.should.be.instanceOf(TinderNotAuthorizedError) 333 | 334 | done() 335 | }) 336 | }) 337 | }) 338 | 339 | describe('when getting user without an access token', () => { 340 | const userId = 'my-user-id' 341 | 342 | beforeEach(() => { 343 | td.replace('request-on-steroids', Request) 344 | 345 | const TinderWrapper = require('../src/tinder-wrapper') 346 | subject = new TinderWrapper() 347 | }) 348 | 349 | it('should reject with tinder not authorized error', (done) => { 350 | subject.getUser(userId) 351 | .catch((error) => { 352 | error.should.be.instanceOf(TinderNotAuthorizedError) 353 | 354 | done() 355 | }) 356 | }) 357 | }) 358 | 359 | describe('when getting user with invalid id', () => { 360 | const userId = undefined 361 | 362 | beforeEach(() => { 363 | const TinderWrapper = require('../src/tinder-wrapper') 364 | subject = new TinderWrapper() 365 | }) 366 | 367 | it('should reject with invalid arguments error', (done) => { 368 | subject.getUser(userId) 369 | .catch((error) => { 370 | error.should.be.instanceOf(Error) 371 | error.message.should.be.equal('invalid arguments') 372 | 373 | done() 374 | }) 375 | }) 376 | }) 377 | 378 | describe('when getting updates with a last activity date', () => { 379 | const lastActivityDate = new Date() 380 | const statusCode = 200 381 | const body = {} 382 | const response = { statusCode, body } 383 | const authToken = 'my-access-token' 384 | 385 | beforeEach(() => { 386 | td.when(Request.prototype.post(td.matchers.anything(), td.callback(response))).thenResolve(body) 387 | td.replace('request-on-steroids', Request) 388 | 389 | const TinderWrapper = require('../src/tinder-wrapper') 390 | subject = new TinderWrapper() 391 | subject.authToken = authToken 392 | }) 393 | 394 | it('should do a post request to https://api.gotinder.com/updates', () => { 395 | return subject.getUpdates(lastActivityDate) 396 | .then(() => { 397 | const captor = td.matchers.captor() 398 | 399 | td.verify(Request.prototype.post(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 400 | 401 | const options = captor.value 402 | options.should.have.property('url', 'https://api.gotinder.com/updates') 403 | }) 404 | }) 405 | 406 | it('should do a post request with body', () => { 407 | return subject.getUpdates(lastActivityDate) 408 | .then(() => { 409 | const captor = td.matchers.captor() 410 | 411 | td.verify(Request.prototype.post(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 412 | 413 | const options = captor.value 414 | options.should.have.nested.property('body.last_activity_date', lastActivityDate.toISOString()) 415 | }) 416 | }) 417 | 418 | it('should resolve with response body as data', () => { 419 | return subject.getUpdates(lastActivityDate) 420 | .then((data) => { 421 | data.should.be.equal(body) 422 | }) 423 | }) 424 | }) 425 | 426 | describe('when getting updates without a last activity date', () => { 427 | const statusCode = 200 428 | const body = {} 429 | const response = { statusCode, body } 430 | const authToken = 'my-access-token' 431 | 432 | beforeEach(() => { 433 | td.when(Request.prototype.post(td.matchers.anything(), td.callback(response))).thenResolve(body) 434 | td.replace('request-on-steroids', Request) 435 | 436 | const TinderWrapper = require('../src/tinder-wrapper') 437 | subject = new TinderWrapper() 438 | subject.authToken = authToken 439 | }) 440 | 441 | it('should do a post request to https://api.gotinder.com/updates', () => { 442 | return subject.getUpdates() 443 | .then(() => { 444 | const captor = td.matchers.captor() 445 | 446 | td.verify(Request.prototype.post(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 447 | 448 | const options = captor.value 449 | options.should.have.property('url', 'https://api.gotinder.com/updates') 450 | }) 451 | }) 452 | 453 | it('should do a post request with body', () => { 454 | return subject.getUpdates() 455 | .then(() => { 456 | const captor = td.matchers.captor() 457 | 458 | td.verify(Request.prototype.post(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 459 | 460 | const options = captor.value 461 | options.should.have.nested.property('body.last_activity_date', '') 462 | }) 463 | }) 464 | 465 | it('should resolve with response body as data', () => { 466 | return subject.getUpdates() 467 | .then((data) => { 468 | data.should.be.equal(body) 469 | }) 470 | }) 471 | }) 472 | 473 | describe('when getting updates with invalid last activity date', () => { 474 | const lastActivityDate = null 475 | 476 | beforeEach(() => { 477 | td.replace('request-on-steroids', Request) 478 | 479 | const TinderWrapper = require('../src/tinder-wrapper') 480 | subject = new TinderWrapper() 481 | }) 482 | 483 | it('should reject with invalid arguments error', (done) => { 484 | subject.getUpdates(lastActivityDate) 485 | .catch((error) => { 486 | error.should.be.instanceOf(Error) 487 | error.message.should.be.equal('invalid arguments') 488 | 489 | done() 490 | }) 491 | }) 492 | }) 493 | 494 | describe('when getting updates and not authorized', () => { 495 | const statusCode = 401 496 | const response = { statusCode } 497 | const authToken = 'my-access-token' 498 | 499 | beforeEach(() => { 500 | td.when(Request.prototype.post(td.matchers.anything(), td.callback(response))).thenResolve() 501 | td.replace('request-on-steroids', Request) 502 | 503 | const TinderWrapper = require('../src/tinder-wrapper') 504 | subject = new TinderWrapper() 505 | subject.authToken = authToken 506 | }) 507 | 508 | it('should reject with tinder not authorized error', (done) => { 509 | subject.getUpdates() 510 | .catch((error) => { 511 | error.should.be.instanceOf(TinderNotAuthorizedError) 512 | 513 | done() 514 | }) 515 | }) 516 | }) 517 | 518 | describe('when getting updates without an access token', () => { 519 | beforeEach(() => { 520 | td.replace('request-on-steroids', Request) 521 | 522 | const TinderWrapper = require('../src/tinder-wrapper') 523 | subject = new TinderWrapper() 524 | }) 525 | 526 | it('should reject with tinder not authorized error', (done) => { 527 | subject.getUpdates() 528 | .catch((error) => { 529 | error.should.be.instanceOf(TinderNotAuthorizedError) 530 | 531 | done() 532 | }) 533 | }) 534 | }) 535 | 536 | describe('when sending message', () => { 537 | const matchId = 'my-match-id' 538 | const message = 'my-message' 539 | const statusCode = 200 540 | const body = {} 541 | const response = { statusCode, body } 542 | const authToken = 'my-access-token' 543 | 544 | beforeEach(() => { 545 | td.when(Request.prototype.post(td.matchers.anything(), td.callback(response))).thenResolve(body) 546 | td.replace('request-on-steroids', Request) 547 | 548 | const TinderWrapper = require('../src/tinder-wrapper') 549 | subject = new TinderWrapper() 550 | subject.authToken = authToken 551 | }) 552 | 553 | it('should do a post request to https://api.gotinder.com/user/matches/my-match-id', () => { 554 | return subject.sendMessage(matchId, message) 555 | .then(() => { 556 | const captor = td.matchers.captor() 557 | 558 | td.verify(Request.prototype.post(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 559 | 560 | const options = captor.value 561 | options.should.have.property('url', 'https://api.gotinder.com/user/matches/my-match-id') 562 | }) 563 | }) 564 | 565 | it('should do a post request with body', () => { 566 | return subject.sendMessage(matchId, message) 567 | .then(() => { 568 | const captor = td.matchers.captor() 569 | 570 | td.verify(Request.prototype.post(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 571 | 572 | const options = captor.value 573 | options.should.have.nested.property('body.message', message) 574 | }) 575 | }) 576 | 577 | it('should resolve with response body as data', () => { 578 | return subject.sendMessage(matchId, message) 579 | .then((data) => { 580 | data.should.be.equal(body) 581 | }) 582 | }) 583 | }) 584 | 585 | describe('when sending message with invalid match id and message', () => { 586 | const matchId = undefined 587 | const message = undefined 588 | 589 | beforeEach(() => { 590 | td.replace('request-on-steroids', Request) 591 | 592 | const TinderWrapper = require('../src/tinder-wrapper') 593 | subject = new TinderWrapper() 594 | }) 595 | 596 | it('should reject with invalid arguments error', (done) => { 597 | subject.sendMessage(matchId, message) 598 | .catch((error) => { 599 | error.should.be.instanceOf(Error) 600 | error.message.should.be.equal('invalid arguments') 601 | 602 | done() 603 | }) 604 | }) 605 | }) 606 | 607 | describe('when sending message and not authorized', () => { 608 | const statusCode = 401 609 | const response = { statusCode } 610 | const authToken = 'my-access-token' 611 | const matchId = 'my-match-id' 612 | const message = 'my-message' 613 | 614 | beforeEach(() => { 615 | td.when(Request.prototype.post(td.matchers.anything(), td.callback(response))).thenResolve() 616 | td.replace('request-on-steroids', Request) 617 | 618 | const TinderWrapper = require('../src/tinder-wrapper') 619 | subject = new TinderWrapper() 620 | subject.authToken = authToken 621 | }) 622 | 623 | it('should reject with tinder not authorized error', (done) => { 624 | subject.sendMessage(matchId, message) 625 | .catch((error) => { 626 | error.should.be.instanceOf(TinderNotAuthorizedError) 627 | 628 | done() 629 | }) 630 | }) 631 | }) 632 | 633 | describe('when sending message without an access token', () => { 634 | const matchId = 'my-match-id' 635 | const message = 'my-message' 636 | 637 | beforeEach(() => { 638 | td.replace('request-on-steroids', Request) 639 | 640 | const TinderWrapper = require('../src/tinder-wrapper') 641 | subject = new TinderWrapper() 642 | }) 643 | 644 | it('should reject with tinder not authorized error', (done) => { 645 | subject.sendMessage(matchId, message) 646 | .catch((error) => { 647 | error.should.be.instanceOf(TinderNotAuthorizedError) 648 | 649 | done() 650 | }) 651 | }) 652 | }) 653 | 654 | describe('when liking', () => { 655 | const userId = 'my-user-id' 656 | const photoId = 'my-photo-id' 657 | const contentHash = 'my-content-hash' 658 | const sNumber = 'my-s-number' 659 | const statusCode = 200 660 | const body = { likes_remaining: 100 } 661 | const response = { statusCode, body } 662 | const authToken = 'my-access-token' 663 | 664 | beforeEach(() => { 665 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve(body) 666 | td.replace('request-on-steroids', Request) 667 | 668 | const TinderWrapper = require('../src/tinder-wrapper') 669 | subject = new TinderWrapper() 670 | subject.authToken = authToken 671 | }) 672 | 673 | it('should do a get request to https://api.gotinder.com/like/my-user-id?photoId=my-photo-id&content_hash=my-content-hash&s_number=my-s-number', () => { 674 | return subject.like(userId, photoId, contentHash, sNumber) 675 | .then(() => { 676 | const captor = td.matchers.captor() 677 | 678 | td.verify(Request.prototype.get(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 679 | 680 | const options = captor.value 681 | options.should.have.property('url', 'https://api.gotinder.com/like/my-user-id?photoId=my-photo-id&content_hash=my-content-hash&s_number=my-s-number') 682 | }) 683 | }) 684 | 685 | it('should resolve with response body as data', () => { 686 | return subject.like(userId, photoId, contentHash, sNumber) 687 | .then((data) => { 688 | data.should.be.equal(body) 689 | }) 690 | }) 691 | }) 692 | 693 | describe('when liking and out of likes', () => { 694 | const userId = 'my-user-id' 695 | const photoId = 'my-photo-id' 696 | const contentHash = 'my-content-hash' 697 | const sNumber = 'my-s-number' 698 | const statusCode = 200 699 | const body = { likes_remaining: 0 } 700 | const response = { statusCode, body } 701 | const authToken = 'my-access-token' 702 | 703 | beforeEach(() => { 704 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve(body) 705 | td.replace('request-on-steroids', Request) 706 | 707 | const TinderWrapper = require('../src/tinder-wrapper') 708 | subject = new TinderWrapper() 709 | subject.authToken = authToken 710 | }) 711 | 712 | it('should reject with tinder out of likes error', (done) => { 713 | subject.like(userId, photoId, contentHash, sNumber) 714 | .catch((error) => { 715 | error.should.be.instanceOf(TinderOutOfLikesError) 716 | 717 | done() 718 | }) 719 | }) 720 | }) 721 | 722 | describe('when liking with invalid user id', () => { 723 | const userId = undefined 724 | 725 | beforeEach(() => { 726 | td.replace('request-on-steroids', Request) 727 | 728 | const TinderWrapper = require('../src/tinder-wrapper') 729 | subject = new TinderWrapper() 730 | }) 731 | 732 | it('should reject with invalid arguments error', (done) => { 733 | subject.like(userId) 734 | .catch((error) => { 735 | error.should.be.instanceOf(Error) 736 | error.message.should.be.equal('invalid arguments') 737 | 738 | done() 739 | }) 740 | }) 741 | }) 742 | 743 | describe('when liking and not authorized', () => { 744 | const statusCode = 401 745 | const response = { statusCode } 746 | const authToken = 'my-access-token' 747 | const userId = 'my-user-id' 748 | const photoId = 'my-photo-id' 749 | const contentHash = 'my-content-hash' 750 | const sNumber = 'my-s-number' 751 | 752 | beforeEach(() => { 753 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve() 754 | td.replace('request-on-steroids', Request) 755 | 756 | const TinderWrapper = require('../src/tinder-wrapper') 757 | subject = new TinderWrapper() 758 | subject.authToken = authToken 759 | }) 760 | 761 | it('should reject with tinder not authorized error', (done) => { 762 | subject.like(userId, photoId, contentHash, sNumber) 763 | .catch((error) => { 764 | error.should.be.instanceOf(TinderNotAuthorizedError) 765 | 766 | done() 767 | }) 768 | }) 769 | }) 770 | 771 | describe('when liking without an access token', () => { 772 | const userId = 'my-user-id' 773 | const photoId = 'my-photo-id' 774 | const contentHash = 'my-content-hash' 775 | const sNumber = 'my-s-number' 776 | 777 | beforeEach(() => { 778 | td.replace('request-on-steroids', Request) 779 | 780 | const TinderWrapper = require('../src/tinder-wrapper') 781 | subject = new TinderWrapper() 782 | }) 783 | 784 | it('should reject with tinder not authorized error', (done) => { 785 | subject.like(userId, photoId, contentHash, sNumber) 786 | .catch((error) => { 787 | error.should.be.instanceOf(TinderNotAuthorizedError) 788 | 789 | done() 790 | }) 791 | }) 792 | }) 793 | 794 | describe('when passing', () => { 795 | const userId = 'my-user-id' 796 | const statusCode = 200 797 | const body = {} 798 | const response = { statusCode, body } 799 | const authToken = 'my-access-token' 800 | 801 | beforeEach(() => { 802 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve(body) 803 | td.replace('request-on-steroids', Request) 804 | 805 | const TinderWrapper = require('../src/tinder-wrapper') 806 | subject = new TinderWrapper() 807 | subject.authToken = authToken 808 | }) 809 | 810 | it('should do a get request to https://api.gotinder.com/pass/my-user-id', () => { 811 | return subject.pass(userId) 812 | .then(() => { 813 | const captor = td.matchers.captor() 814 | 815 | td.verify(Request.prototype.get(captor.capture()), { ignoreExtraArgs: true, times: 1 }) 816 | 817 | const options = captor.value 818 | options.should.have.property('url', 'https://api.gotinder.com/pass/my-user-id') 819 | }) 820 | }) 821 | 822 | it('should resolve with response body as data', () => { 823 | return subject.pass(userId) 824 | .then((data) => { 825 | data.should.be.equal(body) 826 | }) 827 | }) 828 | }) 829 | 830 | describe('when passing with invalid user id', () => { 831 | const userId = undefined 832 | 833 | beforeEach(() => { 834 | td.replace('request-on-steroids', Request) 835 | 836 | const TinderWrapper = require('../src/tinder-wrapper') 837 | subject = new TinderWrapper() 838 | }) 839 | 840 | it('should reject with invalid arguments error', (done) => { 841 | subject.pass(userId) 842 | .catch((error) => { 843 | error.should.be.instanceOf(Error) 844 | error.message.should.be.equal('invalid arguments') 845 | 846 | done() 847 | }) 848 | }) 849 | }) 850 | 851 | describe('when passing and not authorized', () => { 852 | const statusCode = 401 853 | const response = { statusCode } 854 | const authToken = 'my-access-token' 855 | const userId = 'my-user-id' 856 | 857 | beforeEach(() => { 858 | td.when(Request.prototype.get(td.matchers.anything(), td.callback(response))).thenResolve() 859 | td.replace('request-on-steroids', Request) 860 | 861 | const TinderWrapper = require('../src/tinder-wrapper') 862 | subject = new TinderWrapper() 863 | subject.authToken = authToken 864 | }) 865 | 866 | it('should reject with tinder not authorized error', (done) => { 867 | subject.pass(userId) 868 | .catch((error) => { 869 | error.should.be.instanceOf(TinderNotAuthorizedError) 870 | 871 | done() 872 | }) 873 | }) 874 | }) 875 | 876 | describe('when passing without an access token', () => { 877 | const userId = 'my-user-id' 878 | 879 | beforeEach(() => { 880 | td.replace('request-on-steroids', Request) 881 | 882 | const TinderWrapper = require('../src/tinder-wrapper') 883 | subject = new TinderWrapper() 884 | }) 885 | 886 | it('should reject with tinder not authorized error', (done) => { 887 | subject.pass(userId) 888 | .catch((error) => { 889 | error.should.be.instanceOf(TinderNotAuthorizedError) 890 | 891 | done() 892 | }) 893 | }) 894 | }) 895 | }) 896 | --------------------------------------------------------------------------------