From dff81f64a40928bf18140e4d90bd274767a7f585 Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Mon, 14 May 2018 20:44:12 +0100 Subject: [PATCH 01/19] Add chai and mocha for testing --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index df3ca7b..2f694ab 100644 --- a/package.json +++ b/package.json @@ -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" } From 1566a78ae93b20a553d0d610de4acbb0ec559ea3 Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Mon, 14 May 2018 20:44:38 +0100 Subject: [PATCH 02/19] Update package lock --- package-lock.json | 124 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 119 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 26b8a64..4676d07 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", @@ -4007,11 +4120,6 @@ "kind-of": "3.2.2" } }, - "snekfetch": { - "version": "3.6.4", - "resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz", - "integrity": "sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw==" - }, "source-list-map": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.0.tgz", @@ -4337,6 +4445,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", From ace0a50b10f1343c15c2bf14fbcf2b6284165bb7 Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Mon, 14 May 2018 21:05:44 +0100 Subject: [PATCH 03/19] Update package-lock again?? --- package-lock.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package-lock.json b/package-lock.json index 4676d07..e2db8f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4120,6 +4120,11 @@ "kind-of": "3.2.2" } }, + "snekfetch": { + "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", "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.0.tgz", From ca196dc14ba10378900d3fcd200cd6f8108d0c37 Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Mon, 14 May 2018 21:06:15 +0100 Subject: [PATCH 04/19] Add initial Unit test for Players endpoint --- test/Players/Players.js | 13 + test/Players/responses/200.json | 496 ++++++++++++++++++++++++++++++++ test/Players/responses/index.js | 3 + test/index.js | 14 - 4 files changed, 512 insertions(+), 14 deletions(-) create mode 100644 test/Players/Players.js create mode 100644 test/Players/responses/200.json create mode 100644 test/Players/responses/index.js delete mode 100644 test/index.js diff --git a/test/Players/Players.js b/test/Players/Players.js new file mode 100644 index 0000000..46ffa45 --- /dev/null +++ b/test/Players/Players.js @@ -0,0 +1,13 @@ +const expect = require('chai').expect + +const pubg = require('../../') +const responses = require('./responses') + +describe('Players', function() { + describe('200 Response', function() { + var player = new pubg.Player(responses[200]) + it('should be a Player class', function() { + expect(player).to.be.instanceOf(pubg.Player) + }) + }) +}) \ 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/index.js b/test/Players/responses/index.js new file mode 100644 index 0000000..95835c3 --- /dev/null +++ b/test/Players/responses/index.js @@ -0,0 +1,3 @@ +module.exports = { + 200: require('./200.json').data[0] +} \ 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 From 7a34d53f313c50437e6859489cbf0876280cd914 Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Mon, 14 May 2018 21:12:07 +0100 Subject: [PATCH 05/19] Update tests script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2f694ab..5c4c834 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" }, From bd89f7900bec7cc6134532f5af8fa04e35ee6b9a Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Mon, 14 May 2018 21:12:56 +0100 Subject: [PATCH 06/19] Rename file to test.js for simplicity --- test/Players/{Players.js => test.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/Players/{Players.js => test.js} (100%) diff --git a/test/Players/Players.js b/test/Players/test.js similarity index 100% rename from test/Players/Players.js rename to test/Players/test.js From 08fba1eb21825c2bcb165d88bb33a32b6d834bed Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Mon, 14 May 2018 21:49:27 +0100 Subject: [PATCH 07/19] Finish Players test --- test/Players/test.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/Players/test.js b/test/Players/test.js index 46ffa45..31bbe7c 100644 --- a/test/Players/test.js +++ b/test/Players/test.js @@ -5,9 +5,47 @@ const responses = require('./responses') describe('Players', function() { describe('200 Response', function() { - var player = new pubg.Player(responses[200]) + 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 From 734711b2740f4788bacd55385a6eab46170ae651 Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Thu, 17 May 2018 17:17:04 +0100 Subject: [PATCH 08/19] Add 401 response --- src/Client.js | 3 +++ test/Players/responses/401.json | 7 +++++++ test/Players/responses/index.js | 1 + 3 files changed, 11 insertions(+) create mode 100644 test/Players/responses/401.json diff --git a/src/Client.js b/src/Client.js index d4b300c..06879de 100644 --- a/src/Client.js +++ b/src/Client.js @@ -42,6 +42,9 @@ class Client { * @returns {Promise>|Promise} * @memberof Client */ + + // TODO Split these methods into two parts to allow the testing suite to inject dummy data + getPlayer(args, shard = this.defaultShard) { if (typeof args !== 'object' || typeof shard !== 'string') throw new Error('Requires (object, !string)'); 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/index.js b/test/Players/responses/index.js index 95835c3..890039e 100644 --- a/test/Players/responses/index.js +++ b/test/Players/responses/index.js @@ -1,3 +1,4 @@ module.exports = { 200: require('./200.json').data[0] + 401: require('./401.json') } \ No newline at end of file From b6876e60ae7e88cb5ea4cbf41a4187c51ba6c7f6 Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Thu, 17 May 2018 17:19:13 +0100 Subject: [PATCH 09/19] Add 404 response --- test/Players/responses/404.json | 7 +++++++ test/Players/responses/index.js | 1 + 2 files changed, 8 insertions(+) create mode 100644 test/Players/responses/404.json 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 index 890039e..b022cbc 100644 --- a/test/Players/responses/index.js +++ b/test/Players/responses/index.js @@ -1,4 +1,5 @@ module.exports = { 200: require('./200.json').data[0] 401: require('./401.json') + 404: require('./404.json') } \ No newline at end of file From 2014ddb52cf6eb600b382c53bcbc9b34a091bf0f Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Thu, 17 May 2018 18:58:31 +0100 Subject: [PATCH 10/19] Fix responses index file and remove TODO comment because that's not allowed --- src/Client.js | 2 -- test/Players/responses/index.js | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Client.js b/src/Client.js index 06879de..f23f935 100644 --- a/src/Client.js +++ b/src/Client.js @@ -43,8 +43,6 @@ class Client { * @memberof Client */ - // TODO Split these methods into two parts to allow the testing suite to inject dummy data - getPlayer(args, shard = this.defaultShard) { if (typeof args !== 'object' || typeof shard !== 'string') throw new Error('Requires (object, !string)'); diff --git a/test/Players/responses/index.js b/test/Players/responses/index.js index b022cbc..cfbcb53 100644 --- a/test/Players/responses/index.js +++ b/test/Players/responses/index.js @@ -1,5 +1,5 @@ module.exports = { - 200: require('./200.json').data[0] - 401: require('./401.json') + 200: require('./200.json').data[0], + 401: require('./401.json'), 404: require('./404.json') } \ No newline at end of file From eb33a30540eddb39900abbcab82e3b8170e741df Mon Sep 17 00:00:00 2001 From: jamesc24 Date: Wed, 23 May 2018 19:07:37 +0100 Subject: [PATCH 11/19] Add Client unit test, plus a new function that rejects invalid shards --- src/Client.js | 2 ++ test/Client/test.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/Client/test.js diff --git a/src/Client.js b/src/Client.js index f23f935..83a89a0 100644 --- a/src/Client.js +++ b/src/Client.js @@ -17,6 +17,8 @@ class Client { constructor(key, defaultShard = 'pc-oc') { if (!key) { throw new Error('No API key passed.'); + } else if (!(Util.verifyShard(defaultShard))) { + throw new Error('Invalid shard.') } /** diff --git a/test/Client/test.js b/test/Client/test.js new file mode 100644 index 0000000..b2ef28a --- /dev/null +++ b/test/Client/test.js @@ -0,0 +1,32 @@ +const expect = require('chai').expect + +const pubg = require('../../') + +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', 'No API key passed.') + }) + + 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', 'Invalid shard.') + }) + + it('should store the API key and shard correctly', function() { + ApiKey = 'mykey' + 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('mykey') + expect(client).to.have.property('defaultShard', 'pc-oc') + }) +}) \ No newline at end of file From fdd485d48dfbcc514a0d77c0b3a448be31c1bbcb Mon Sep 17 00:00:00 2001 From: jamesc24 <35628223+Boserr@users.noreply.github.com> Date: Wed, 23 May 2018 19:15:54 +0100 Subject: [PATCH 12/19] Fix code to comply with eslint --- src/Client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.js b/src/Client.js index 83a89a0..f16c11d 100644 --- a/src/Client.js +++ b/src/Client.js @@ -17,8 +17,8 @@ class Client { constructor(key, defaultShard = 'pc-oc') { if (!key) { throw new Error('No API key passed.'); - } else if (!(Util.verifyShard(defaultShard))) { - throw new Error('Invalid shard.') + } else if (!Util.verifyShard(defaultShard)) { + throw new Error('Invalid shard.'); } /** From 5009c8253a18b69f348211120dfd839bbdf7a818 Mon Sep 17 00:00:00 2001 From: jamesc24 <35628223+Boserr@users.noreply.github.com> Date: Wed, 23 May 2018 19:40:01 +0100 Subject: [PATCH 13/19] Put Client error messages in external constants file, to keep tests consistent in the future --- src/Client.js | 5 +++-- src/util/Errors.js | 4 ++++ test/Client/test.js | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 src/util/Errors.js diff --git a/src/Client.js b/src/Client.js index f16c11d..5f20022 100644 --- a/src/Client.js +++ b/src/Client.js @@ -2,6 +2,7 @@ const snekfetch = require('snekfetch'); const Package = require('../package.json'); const Util = require('./util/Util'); +const Errors = require('./util/Errors'); const Player = require('./Player'); const Match = require('./matches/Match'); const Status = require('./Status'); @@ -16,9 +17,9 @@ const PlayerSeason = require('./playerseason/PlayerSeason'); class Client { constructor(key, defaultShard = 'pc-oc') { if (!key) { - throw new Error('No API key passed.'); + throw new Error(Errors.NO_API_KEY); } else if (!Util.verifyShard(defaultShard)) { - throw new Error('Invalid shard.'); + throw new Error(Errors.INVALID_SHARD_ID); } /** diff --git a/src/util/Errors.js b/src/util/Errors.js new file mode 100644 index 0000000..2ad7af6 --- /dev/null +++ b/src/util/Errors.js @@ -0,0 +1,4 @@ +module.exports = { + NO_API_KEY: 'No API key provided', + INVALID_SHARD_ID: 'Invalid shard/region ID provided', +}; diff --git a/test/Client/test.js b/test/Client/test.js index b2ef28a..5a9b9f1 100644 --- a/test/Client/test.js +++ b/test/Client/test.js @@ -1,6 +1,7 @@ const expect = require('chai').expect const pubg = require('../../') +const Errors = require('../../src/util/Errors') const Client = pubg.Client @@ -8,13 +9,13 @@ 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', 'No API key passed.') + }).to.throw(Error).with.property('message', Errors.NO_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', 'Invalid shard.') + }).to.throw(Error).with.property('message', Errors.INVALID_SHARD_ID) }) it('should store the API key and shard correctly', function() { From 440170d64b2f479298a40462dbddffcfba5618f7 Mon Sep 17 00:00:00 2001 From: jamesc24 <35628223+Boserr@users.noreply.github.com> Date: Wed, 23 May 2018 19:53:01 +0100 Subject: [PATCH 14/19] Move default shard into constants file, should it ever need to be changed --- src/Client.js | 3 ++- src/util/Constants.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Client.js b/src/Client.js index d4b300c..92bb032 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1,6 +1,7 @@ const snekfetch = require('snekfetch'); const Package = require('../package.json'); +const Constants = require('./util/Constants'); const Util = require('./util/Util'); const Player = require('./Player'); const Match = require('./matches/Match'); @@ -14,7 +15,7 @@ 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.'); } diff --git a/src/util/Constants.js b/src/util/Constants.js index e8fd3c8..6343bc7 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', From 2dee0833114515bb4bd3b51713c30190c2e422b4 Mon Sep 17 00:00:00 2001 From: jamesc24 <35628223+Boserr@users.noreply.github.com> Date: Wed, 23 May 2018 19:58:38 +0100 Subject: [PATCH 15/19] Implement default shard constant into tests --- test/Client/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Client/test.js b/test/Client/test.js index 5a9b9f1..2253f47 100644 --- a/test/Client/test.js +++ b/test/Client/test.js @@ -2,6 +2,7 @@ const expect = require('chai').expect const pubg = require('../../') const Errors = require('../../src/util/Errors') +const Constants = require('../../src/util/Constants') const Client = pubg.Client @@ -28,6 +29,6 @@ describe('Client', function() { it('should set a defaultShard if one is not specified', function() { client = new Client('mykey') - expect(client).to.have.property('defaultShard', 'pc-oc') + expect(client).to.have.property('defaultShard', Constants.DEFAULT_SHARD) }) }) \ No newline at end of file From 856fe651b78585fd89743cfbf5f9f91c7e52d158 Mon Sep 17 00:00:00 2001 From: James <35628223+Boserr@users.noreply.github.com> Date: Wed, 23 May 2018 22:53:51 +0100 Subject: [PATCH 16/19] Remove the random blank line --- src/Client.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Client.js b/src/Client.js index 5fec020..658f0a1 100644 --- a/src/Client.js +++ b/src/Client.js @@ -46,7 +46,6 @@ class Client { * @returns {Promise>|Promise} * @memberof Client */ - getPlayer(args, shard = this.defaultShard) { if (typeof args !== 'object' || typeof shard !== 'string') throw new Error('Requires (object, !string)'); From e1608ff951aca4f08193e9cd10fa2c21bb082def Mon Sep 17 00:00:00 2001 From: jamesc24 <35628223+Boserr@users.noreply.github.com> Date: Thu, 24 May 2018 09:05:59 +0100 Subject: [PATCH 17/19] Add invalid API key logic --- src/Client.js | 2 ++ src/util/Errors.js | 2 ++ test/Client/test.js | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/src/Client.js b/src/Client.js index 5fec020..4d7ba02 100644 --- a/src/Client.js +++ b/src/Client.js @@ -19,6 +19,8 @@ class Client { constructor(key, defaultShard = Constants.DEFAULT_SHARD) { if (!key) { 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.INVALID_SHARD_ID); } diff --git a/src/util/Errors.js b/src/util/Errors.js index 2ad7af6..ce799d3 100644 --- a/src/util/Errors.js +++ b/src/util/Errors.js @@ -1,4 +1,6 @@ module.exports = { NO_API_KEY: 'No API key provided', + INVALID_SHARD_ID: 'Invalid shard/region ID provided', + INVALID_API_KEY: 'Invalid API key provided', }; diff --git a/test/Client/test.js b/test/Client/test.js index 2253f47..1efa928 100644 --- a/test/Client/test.js +++ b/test/Client/test.js @@ -13,6 +13,12 @@ describe('Client', function() { }).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') From 5068ac55e7e5c5d681e4c20c1b58529dcadeb464 Mon Sep 17 00:00:00 2001 From: jamesc24 <35628223+Boserr@users.noreply.github.com> Date: Thu, 24 May 2018 09:20:49 +0100 Subject: [PATCH 18/19] Change api key in test scripts to be consistent --- test/Client/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Client/test.js b/test/Client/test.js index 1efa928..99973d8 100644 --- a/test/Client/test.js +++ b/test/Client/test.js @@ -26,7 +26,7 @@ describe('Client', function() { }) it('should store the API key and shard correctly', function() { - ApiKey = 'mykey' + ApiKey = 'non-existent-key' region = 'pc-na' client = new Client(ApiKey, region) expect(client).to.have.property('key').that.equals(ApiKey) @@ -34,7 +34,7 @@ describe('Client', function() { }) it('should set a defaultShard if one is not specified', function() { - client = new Client('mykey') + client = new Client('non-existent-key') expect(client).to.have.property('defaultShard', Constants.DEFAULT_SHARD) }) }) \ No newline at end of file From cd251b89ce9da6878aa9bba59b70d1ae3fc59fcf Mon Sep 17 00:00:00 2001 From: jamesc24 <35628223+Boserr@users.noreply.github.com> Date: Thu, 24 May 2018 09:29:12 +0100 Subject: [PATCH 19/19] Change error message for shard IDs --- src/Client.js | 2 +- src/util/Errors.js | 2 ++ test/Client/test.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Client.js b/src/Client.js index 141abdd..43ad03f 100644 --- a/src/Client.js +++ b/src/Client.js @@ -22,7 +22,7 @@ class Client { } else if (typeof key !== 'string') { throw new Error(Errors.INVALID_API_KEY); } else if (!Util.verifyShard(defaultShard)) { - throw new Error(Errors.INVALID_SHARD_ID); + throw new Error(Errors.NON_EXISTENT_SHARD_ID); } /** diff --git a/src/util/Errors.js b/src/util/Errors.js index ce799d3..83bab10 100644 --- a/src/util/Errors.js +++ b/src/util/Errors.js @@ -3,4 +3,6 @@ module.exports = { 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 index 99973d8..0dda4cd 100644 --- a/test/Client/test.js +++ b/test/Client/test.js @@ -22,7 +22,7 @@ describe('Client', function() { 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.INVALID_SHARD_ID) + }).to.throw(Error).with.property('message', Errors.NON_EXISTENT_SHARD_ID) }) it('should store the API key and shard correctly', function() {