diff --git a/package-lock.json b/package-lock.json index 1f3a0ce..94dd88f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -181,6 +181,12 @@ "util": "0.10.3" } }, + "assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true + }, "assign-symbols": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz", @@ -391,6 +397,12 @@ "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=", "dev": true }, + "browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", + "dev": true + }, "browserify-aes": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", @@ -574,6 +586,20 @@ "lazy-cache": "1.0.4" } }, + "chai": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz", + "integrity": "sha1-D2RYS6ZC8PKs4oBiefTwbKI61zw=", + "dev": true, + "requires": { + "assertion-error": "1.1.0", + "check-error": "1.0.2", + "deep-eql": "3.0.1", + "get-func-name": "2.0.0", + "pathval": "1.1.0", + "type-detect": "4.0.8" + } + }, "chalk": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", @@ -611,6 +637,12 @@ "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", "dev": true }, + "check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "dev": true + }, "chokidar": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.0.3.tgz", @@ -933,6 +965,15 @@ "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", "dev": true }, + "deep-eql": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "dev": true, + "requires": { + "type-detect": "4.0.8" + } + }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -1011,6 +1052,12 @@ "minimalistic-assert": "1.0.1" } }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true + }, "diffie-hellman": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", @@ -2180,6 +2227,12 @@ "integrity": "sha1-9wLmMSfn4jHBYKgMFVSstw1QR+U=", "dev": true }, + "get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "dev": true + }, "get-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", @@ -2253,6 +2306,12 @@ "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", "dev": true }, + "growl": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", + "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==", + "dev": true + }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", @@ -2320,6 +2379,12 @@ "minimalistic-assert": "1.0.1" } }, + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -2993,6 +3058,48 @@ "minimist": "0.0.8" } }, + "mocha": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.1.1.tgz", + "integrity": "sha512-kKKs/H1KrMMQIEsWNxGmb4/BGsmj0dkeyotEvbrAuQ01FcWRLssUNXCEUZk6SZtyJBi6EE7SL0zDDtItw1rGhw==", + "dev": true, + "requires": { + "browser-stdout": "1.3.1", + "commander": "2.11.0", + "debug": "3.1.0", + "diff": "3.5.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.3", + "he": "1.1.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "supports-color": "4.4.0" + }, + "dependencies": { + "commander": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", + "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", + "dev": true + }, + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", + "dev": true + }, + "supports-color": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", + "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", + "dev": true, + "requires": { + "has-flag": "2.0.0" + } + } + } + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", @@ -3368,6 +3475,12 @@ "pify": "2.3.0" } }, + "pathval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "dev": true + }, "pbkdf2": { "version": "3.0.16", "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.16.tgz", @@ -4008,9 +4121,9 @@ } }, "snekfetch": { - "version": "3.6.4", - "resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz", - "integrity": "sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw==" + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-4.0.0.tgz", + "integrity": "sha512-T1Z9A69uet/Ti69Rmr2U6ZeU6VreucawFSB61tlA+lIARFSBuUxQgFWpVVa47KQgfyyBOJA5midBk7IfhlvelQ==" }, "source-list-map": { "version": "2.0.0", @@ -4337,6 +4450,12 @@ "prelude-ls": "1.1.2" } }, + "type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true + }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", diff --git a/package.json b/package.json index 3c2ce07..7a002e9 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "npm run lint && npm run tests", "lint": "eslint src *.js", - "tests": "node test/index.js", + "tests": "mocha \"test/**/*.js\"", "webpack": "./node_modules/.bin/webpack --config webpack.config.js", "docs": "./node_modules/.bin/jsdoc src src/matches src/playerseason README.md -t ./node_modules/minami && echo pubg.js.org > ./out/CNAME" }, @@ -30,9 +30,11 @@ "snekfetch": "^4.0.0" }, "devDependencies": { + "chai": "^4.1.2", "eslint": "^4.19.1", "jsdoc": "^3.5.5", "minami": "^1.2.3", + "mocha": "^5.1.1", "uglifyjs-webpack-plugin": "^1.2.5", "webpack": "^3.11.0" } diff --git a/src/Client.js b/src/Client.js index d4b300c..43ad03f 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1,7 +1,9 @@ const snekfetch = require('snekfetch'); const Package = require('../package.json'); +const Constants = require('./util/Constants'); const Util = require('./util/Util'); +const Errors = require('./util/Errors'); const Player = require('./Player'); const Match = require('./matches/Match'); const Status = require('./Status'); @@ -14,9 +16,13 @@ const PlayerSeason = require('./playerseason/PlayerSeason'); * @param {string} [defaultShard='pc-oc'] Default shard to use if none provided in methods */ class Client { - constructor(key, defaultShard = 'pc-oc') { + constructor(key, defaultShard = Constants.DEFAULT_SHARD) { if (!key) { - throw new Error('No API key passed.'); + throw new Error(Errors.NO_API_KEY); + } else if (typeof key !== 'string') { + throw new Error(Errors.INVALID_API_KEY); + } else if (!Util.verifyShard(defaultShard)) { + throw new Error(Errors.NON_EXISTENT_SHARD_ID); } /** diff --git a/src/util/Constants.js b/src/util/Constants.js index 0c6e865..a56acce 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -1,6 +1,8 @@ module.exports = { BASE_URL: 'https://api.playbattlegrounds.com', + DEFAULT_SHARD: 'pc-oc', + SHARDS: [ 'xbox-as', 'xbox-eu', diff --git a/src/util/Errors.js b/src/util/Errors.js new file mode 100644 index 0000000..83bab10 --- /dev/null +++ b/src/util/Errors.js @@ -0,0 +1,8 @@ +module.exports = { + NO_API_KEY: 'No API key provided', + + INVALID_SHARD_ID: 'Invalid shard/region ID provided', + INVALID_API_KEY: 'Invalid API key provided', + + NON_EXISTENT_SHARD_ID: 'Shard/region ID provided does not exist', +}; diff --git a/test/Client/test.js b/test/Client/test.js new file mode 100644 index 0000000..0dda4cd --- /dev/null +++ b/test/Client/test.js @@ -0,0 +1,40 @@ +const expect = require('chai').expect + +const pubg = require('../../') +const Errors = require('../../src/util/Errors') +const Constants = require('../../src/util/Constants') + +const Client = pubg.Client + +describe('Client', function() { + it('should throw an error when an API key is not passed to it', function() { + expect(function() { + client = new Client() + }).to.throw(Error).with.property('message', Errors.NO_API_KEY) + }) + + it('should throw an error when a non-string is passed as an API key', function() { + expect(function() { + client = new Client(123) + }).to.throw(Error).with.property('message', Errors.INVALID_API_KEY) + }) + + it('should throw an error if an invalid region is passed to it', function() { + expect(function() { + client = new Client('non-existent-key', 'france') + }).to.throw(Error).with.property('message', Errors.NON_EXISTENT_SHARD_ID) + }) + + it('should store the API key and shard correctly', function() { + ApiKey = 'non-existent-key' + region = 'pc-na' + client = new Client(ApiKey, region) + expect(client).to.have.property('key').that.equals(ApiKey) + expect(client).to.have.property('defaultShard').that.equals(region) + }) + + it('should set a defaultShard if one is not specified', function() { + client = new Client('non-existent-key') + expect(client).to.have.property('defaultShard', Constants.DEFAULT_SHARD) + }) +}) \ No newline at end of file diff --git a/test/Players/responses/200.json b/test/Players/responses/200.json new file mode 100644 index 0000000..95896e0 --- /dev/null +++ b/test/Players/responses/200.json @@ -0,0 +1,496 @@ +{ + "data": [ + { + "type": "player", + "id": "account.d50fdc18fcad49c691d38466bed6f8fd", + "attributes": { + "updatedAt": "2018-05-04T00:19:25Z", + "patchVersion": "", + "name": "shroud", + "stats": null, + "titleId": "bluehole-pubg", + "shardId": "pc-na", + "createdAt": "2018-05-04T00:19:25Z" + }, + "relationships": { + "assets": { + "data": [] + }, + "matches": { + "data": [ + { + "type": "match", + "id": "c0851a5a-9cd5-42ce-bc60-53b1145c3625" + }, + { + "type": "match", + "id": "da876121-8fc0-4672-bff7-28e835fcc8d5" + }, + { + "type": "match", + "id": "a4177404-c262-4dee-8286-12ff44dcb4e1" + }, + { + "type": "match", + "id": "a2993d22-932c-4df3-a998-2084281daf51" + }, + { + "type": "match", + "id": "1fa444f0-c3b1-42f7-8733-e29d1adafcc7" + }, + { + "type": "match", + "id": "73a4adfb-7569-43c8-9a41-42ca509b9dad" + }, + { + "type": "match", + "id": "10b77dc2-850f-4120-83b0-2a91217b53cd" + }, + { + "type": "match", + "id": "bd5bcd0c-2ce6-4ee0-a5d6-a9e7b5fd2468" + }, + { + "type": "match", + "id": "2160031a-af92-4c1c-9fa1-899bd4f81724" + }, + { + "type": "match", + "id": "c9e9dc54-37b6-4c14-adc2-b07e4a9696b4" + }, + { + "type": "match", + "id": "2c296c6e-edd9-419d-b788-4a3d6b1e5161" + }, + { + "type": "match", + "id": "731857e9-ab0d-46ad-b717-8b40144e6e14" + }, + { + "type": "match", + "id": "9b06e1a4-c341-470e-a4b7-deb874c3eb76" + }, + { + "type": "match", + "id": "6372ff7d-b80c-4d3a-95b1-05032fcc247b" + }, + { + "type": "match", + "id": "064af769-5962-4051-9619-f76a81649462" + }, + { + "type": "match", + "id": "9905c07c-1b6b-45f9-a587-9ab4788cc43e" + }, + { + "type": "match", + "id": "1a3f2fdb-bed9-4fb3-8a16-a8a22de37b0a" + }, + { + "type": "match", + "id": "b4ed1f61-63a9-4417-b0cf-b2dc67e27b58" + }, + { + "type": "match", + "id": "a539f2e5-67ba-4271-bf48-850caa534feb" + }, + { + "type": "match", + "id": "a5567cb6-b60d-4b1f-b2af-31286115d296" + }, + { + "type": "match", + "id": "ad2a52cc-1758-4625-8602-44bdd5aef8e8" + }, + { + "type": "match", + "id": "af1dc538-0fca-4d30-bfa3-1afbed31d81c" + }, + { + "type": "match", + "id": "646acedd-dbe6-48c3-b096-f30963deace4" + }, + { + "type": "match", + "id": "182b0665-6859-4da6-bf96-6c7ff04ff7f1" + }, + { + "type": "match", + "id": "5a9bd7d4-c8b2-49f7-b268-c8788d12700b" + }, + { + "type": "match", + "id": "4b6d3d87-490b-464e-bac4-f40728701c17" + }, + { + "type": "match", + "id": "c7fe1d58-f13c-45b9-a9b8-7339ebe84a70" + }, + { + "type": "match", + "id": "2be79c9d-73f9-4ae0-96da-bb8d947d478d" + }, + { + "type": "match", + "id": "5f286b76-06c1-463e-a84a-8fb1bcc55422" + }, + { + "type": "match", + "id": "53fa9227-69b0-433c-b26c-ddb315ed99fb" + }, + { + "type": "match", + "id": "d849aa75-e066-4185-9e7e-76c0062eb58a" + }, + { + "type": "match", + "id": "6b051e58-f2de-43c0-b1f0-9935a1cc60bb" + }, + { + "type": "match", + "id": "401a29ec-bdb7-46a0-88d0-989c64637eba" + }, + { + "type": "match", + "id": "c8d59cde-d63a-4a84-bb12-c5a40c48fc90" + }, + { + "type": "match", + "id": "fbe01350-3461-451a-b411-e1d66c378cd2" + }, + { + "type": "match", + "id": "39e5b09e-316f-4d21-a2e1-2af749aae094" + }, + { + "type": "match", + "id": "37d72d9d-c82d-47c9-ab38-1cc36ebdcc76" + }, + { + "type": "match", + "id": "b428a2f1-70b3-4caa-9cb8-86e16c8b5332" + }, + { + "type": "match", + "id": "58729fdd-d407-4c12-9d71-6e42e9fe2e7c" + }, + { + "type": "match", + "id": "8f272e97-052b-485d-9cd7-45ba2cce1a4e" + }, + { + "type": "match", + "id": "711d6741-a836-493a-ab82-953fc8935157" + }, + { + "type": "match", + "id": "a3552971-6c76-47c8-b75a-544f8b063427" + }, + { + "type": "match", + "id": "f1de79b3-5788-4a31-9707-a5ce46b6e080" + }, + { + "type": "match", + "id": "f29718a9-a053-40b7-9f28-c3c30996a4e4" + }, + { + "type": "match", + "id": "6f6a0bf3-8ad3-468e-a315-c903da011473" + }, + { + "type": "match", + "id": "0ce5a102-1ef4-4b34-9562-9ef2bd2ed0b7" + }, + { + "type": "match", + "id": "3048a2c1-0687-448c-8704-602be2cd8071" + }, + { + "type": "match", + "id": "ffb66434-d544-424c-863b-eb8658f774b8" + }, + { + "type": "match", + "id": "18fd690d-aa40-4693-8ee2-cfc98743cadd" + }, + { + "type": "match", + "id": "ea76e3aa-fa87-4dcd-b4a6-1bdd432c9c0c" + }, + { + "type": "match", + "id": "49dbf2c0-34f7-47aa-9f21-25bead749a06" + }, + { + "type": "match", + "id": "b1f85e77-35b2-4b34-8cd4-f178c9145d05" + }, + { + "type": "match", + "id": "ca309960-cc99-4140-bb0c-5ce3d9b8e3ed" + }, + { + "type": "match", + "id": "ee5a198c-9064-4780-9875-c2cef6a08848" + }, + { + "type": "match", + "id": "b0a9ade5-c95f-427f-b45f-caa5a146a001" + }, + { + "type": "match", + "id": "ab7f88fa-c300-444e-93ab-4bf3eee3f52b" + }, + { + "type": "match", + "id": "9fd178c2-b85a-49ed-807d-177485e7cc73" + }, + { + "type": "match", + "id": "0e1fbf9d-b2a3-4c3c-a1c4-abaa3f4ccdbe" + }, + { + "type": "match", + "id": "5ae8521f-ab6c-4970-89db-c2d47962475a" + }, + { + "type": "match", + "id": "2b0b75af-8bfe-4cc8-b8b8-7c4e14bd892f" + }, + { + "type": "match", + "id": "c539f123-f28f-4dc0-8c92-c40ff052a7ae" + }, + { + "type": "match", + "id": "566f2324-387e-4124-921e-478cafcdbed9" + }, + { + "type": "match", + "id": "4e2fc99b-2cbf-4fef-b652-2c92c1ade5d1" + }, + { + "type": "match", + "id": "975945d3-2349-4ad0-85c9-78d3bad85c1f" + }, + { + "type": "match", + "id": "d63777f4-6537-49d5-9059-183e7443bbd4" + }, + { + "type": "match", + "id": "7553198c-b5f2-4aab-8ad3-405a84e143d3" + }, + { + "type": "match", + "id": "f7a4f858-2d4a-44b7-977a-4e47e6f8edc6" + }, + { + "type": "match", + "id": "98f5b9a3-3166-42d0-aaf4-4725be61a0c6" + }, + { + "type": "match", + "id": "f7d56252-e07c-46aa-a123-d8486a4a5dc9" + }, + { + "type": "match", + "id": "301013f2-9f31-4b56-8deb-e169beda0dbc" + }, + { + "type": "match", + "id": "63d89388-3326-4ed2-bd42-6e98a98e1c58" + }, + { + "type": "match", + "id": "f0ed76fe-9f12-4b97-8288-eff67a7f32af" + }, + { + "type": "match", + "id": "3063b09c-9e08-4b46-a763-12baf0c7e821" + }, + { + "type": "match", + "id": "8e20037c-b573-4e11-8ac3-5eb982b9ac8a" + }, + { + "type": "match", + "id": "5dfaa60f-6c47-44e6-bbb8-bc7cf733d4cb" + }, + { + "type": "match", + "id": "4bfa0e1e-11e1-4c20-b3de-cd1f1b96e339" + }, + { + "type": "match", + "id": "bccc0c6c-1281-4f3c-8d69-ba110e8060c2" + }, + { + "type": "match", + "id": "8a7d6da2-3157-4f7c-94a6-ad2d8a117ecb" + }, + { + "type": "match", + "id": "d38191cf-8a2e-4ff1-848a-ae92bf45317b" + }, + { + "type": "match", + "id": "b93a759c-ec79-404a-8f86-c22c43e5e86f" + }, + { + "type": "match", + "id": "ab548f19-6dca-4c2a-bca1-74664981078b" + }, + { + "type": "match", + "id": "9ad2332f-2ed0-4094-b16e-ac66a43d89b1" + }, + { + "type": "match", + "id": "e7f9037c-1df6-44b7-9dd7-31b6c04936d2" + }, + { + "type": "match", + "id": "ba8eb93f-8473-4775-8448-7d2281773da6" + }, + { + "type": "match", + "id": "e7686895-66ac-459b-9692-84c42f766dd9" + }, + { + "type": "match", + "id": "716e2245-2cd7-4d87-9d61-59d0c88eb9d6" + }, + { + "type": "match", + "id": "d85878c3-334c-4dfe-b4bc-3a8707a57f4b" + }, + { + "type": "match", + "id": "00d7a395-c545-4107-a383-beea4290780c" + }, + { + "type": "match", + "id": "89118657-148b-4323-b2c4-b51f20ea78d4" + }, + { + "type": "match", + "id": "98c170a9-afdf-412c-9771-3f365f16d5f5" + }, + { + "type": "match", + "id": "5a3b789d-d186-49dd-9442-1b03d13b03bc" + }, + { + "type": "match", + "id": "d6671a39-4382-4be3-b422-ae87c98631e5" + }, + { + "type": "match", + "id": "a795eb0a-b68f-459a-ac0c-b255e9f82847" + }, + { + "type": "match", + "id": "79be6c2f-6ff8-4295-b61f-0b60944712d8" + }, + { + "type": "match", + "id": "1f77382f-8f99-43e2-8ed8-8fae6d668835" + }, + { + "type": "match", + "id": "76627494-f05c-4edd-90fd-0eddecfbd476" + }, + { + "type": "match", + "id": "19c01107-e26f-4a0a-b14b-0f59c4da2cba" + }, + { + "type": "match", + "id": "9ab27a92-1f02-47d2-9fe0-58ce9a223046" + }, + { + "type": "match", + "id": "71a55b93-b351-4b6d-b27c-ebc98a752e77" + }, + { + "type": "match", + "id": "2f616f8f-72e4-4395-af50-ab924811be39" + }, + { + "type": "match", + "id": "b3e160be-e628-4eeb-9c25-fb1d010f8755" + }, + { + "type": "match", + "id": "0eeb120f-ef04-426d-88ac-76a40a18fd98" + }, + { + "type": "match", + "id": "8472707e-fb3a-4c14-b7c4-e73b23d67500" + }, + { + "type": "match", + "id": "5bff2e26-c5e2-4712-8e01-c0869df34f81" + }, + { + "type": "match", + "id": "590e1de3-0628-4179-ac1e-582b80f510af" + }, + { + "type": "match", + "id": "f5c5baba-72d5-4aca-b071-8fcdb0149ddc" + }, + { + "type": "match", + "id": "fdbfe804-f0ca-451a-89a4-2bb2e9485256" + }, + { + "type": "match", + "id": "6826ffe2-1d0f-4fdc-b9d3-b7914cfc00ad" + }, + { + "type": "match", + "id": "4aa3fed2-7a21-4530-aafe-afa9bc523beb" + }, + { + "type": "match", + "id": "4008fcce-99ce-41db-a253-8acc0de6d600" + }, + { + "type": "match", + "id": "46d0efa8-8827-45fa-b1ca-a32015263170" + }, + { + "type": "match", + "id": "b3690ffc-0f98-474e-b9d5-3aab399feac8" + }, + { + "type": "match", + "id": "bb8bb4fd-dfff-409d-9150-94540ddaab37" + }, + { + "type": "match", + "id": "14ad1f5d-63e1-4213-b07f-45450e315368" + }, + { + "type": "match", + "id": "dd6f9662-dc0c-4149-8d08-ea597971ef38" + } + ] + } + }, + "links": { + "self": +"https://api.playbattlegrounds.com/shards/pc-na/players/account.d50fdc18fcad49c691d38466bed6f8fd", + "schema": "" + } + } + ], + "links": { + "self": +"https://api.playbattlegrounds.com/shards/pc-na/players?filter[playerNames]=shroud" + }, + "meta": {} +} diff --git a/test/Players/responses/401.json b/test/Players/responses/401.json new file mode 100644 index 0000000..eb117b5 --- /dev/null +++ b/test/Players/responses/401.json @@ -0,0 +1,7 @@ +{ + "errors": [ + { + "title": "Unauthorized" + } + ] +} \ No newline at end of file diff --git a/test/Players/responses/404.json b/test/Players/responses/404.json new file mode 100644 index 0000000..ad0a7be --- /dev/null +++ b/test/Players/responses/404.json @@ -0,0 +1,7 @@ +{ + "errors": [ + { + "title": "Not Found" + } + ] +} \ No newline at end of file diff --git a/test/Players/responses/index.js b/test/Players/responses/index.js new file mode 100644 index 0000000..cfbcb53 --- /dev/null +++ b/test/Players/responses/index.js @@ -0,0 +1,5 @@ +module.exports = { + 200: require('./200.json').data[0], + 401: require('./401.json'), + 404: require('./404.json') +} \ No newline at end of file diff --git a/test/Players/test.js b/test/Players/test.js new file mode 100644 index 0000000..31bbe7c --- /dev/null +++ b/test/Players/test.js @@ -0,0 +1,51 @@ +const expect = require('chai').expect + +const pubg = require('../../') +const responses = require('./responses') + +describe('Players', function() { + describe('200 Response', function() { + const data = responses[200] + const player = new pubg.Player(data) + it('should be a Player class', function() { + expect(player).to.be.instanceOf(pubg.Player) + }) + + it('should have a valid ID', function() { + expect(player).to.have.property('id', data.id) + expect(player.id).to.be.a('string') + }) + + it('should have a valid assets property', function() { + expect(player.relationships).to.have.property('assets').and.to.be.an('array') + }) + + it('should have a valid matches array', function() { + expect(player.relationships).to.have.property('matches').and.to.be.an('array') + }) + + describe('Attributes', function() { + const attributes = player.attributes + it('should have a valid name', function() { + expect(attributes).to.have.property('name', data.attributes.name).and.to.be.a('string') + + }) + + it('should have a valid shardId', function() { + expect(attributes).to.have.property('shardId', data.attributes.shardId).and.to.be.a('string') + }) + + it('should have a valid creation date', function() { + expect(attributes).to.have.property('createdAt').and.to.be.a('Date') + }) + + it('should have a valid patch version', function() { + expect(attributes).to.have.property('patchVersion', data.attributes.patchVersion).and.to.be.a('string') + }) + + it('should have a valid titleId', function() { + expect(attributes).to.have.property('titleId', data.attributes.titleId).and.to.be.a('string') + }) + }) + }) +}) \ No newline at end of file diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 759a3a4..0000000 --- a/test/index.js +++ /dev/null @@ -1,14 +0,0 @@ -const pubg = require('../'); - -const client = new pubg.Client(process.env.PUBG_KEY); - -console.log(`Testing version ${pubg.version} of pubg.js`); - -client.getPlayer({ name: 'NAME THAT WONT EXIST 1233166' }) - .catch(() => console.log('test 1 passed')); - -client.getStatus() - .then(() => console.log('test 1 passed')) - -client.getMatch('not an id') - .catch(() => console.log('test 1 passed')); \ No newline at end of file