@coorpacademy/app-review 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { Rank } from '../types/common';
2
+ export declare const fetchRank: (token: string) => Promise<Rank>;
@@ -0,0 +1,10 @@
1
+ import crossFetch from 'cross-fetch';
2
+ import decode from 'jwt-decode';
3
+ import { toJSON } from './tools/fetch-responses';
4
+ export const fetchRank = async (token) => {
5
+ const { user: userId, host } = decode(token);
6
+ const response = await crossFetch(`${host}/api/v1/leaderboard/rank/${userId}?group=ALL`, {
7
+ headers: { authorization: token }
8
+ });
9
+ return toJSON(response);
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import test from 'ava';
2
+ import nock from 'nock';
3
+ import { fetchRank } from '../fetch-rank';
4
+ const result = {
5
+ rank: 93
6
+ };
7
+ test.before(() => {
8
+ nock('http://localhost:3000')
9
+ .get('/api/v1/leaderboard/rank/592d830b240b923f00bffba6?group=ALL')
10
+ .reply(200, result);
11
+ });
12
+ test.after(() => {
13
+ nock.cleanAll();
14
+ });
15
+ test('should fetch rank with success', async (t) => {
16
+ const token = process.env.API_TEST_TOKEN || '';
17
+ const rank = await fetchRank(token);
18
+ t.deepEqual(result, rank);
19
+ });
20
+ test('should reject bad token', async (t) => {
21
+ const badToken = 'token is not a jwt';
22
+ const error = await t.throwsAsync(() => fetchRank(badToken));
23
+ t.is(error?.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
24
+ });
@@ -74,6 +74,9 @@ export declare type SlideFromAPI = {
74
74
  type: 'chapter' | 'course';
75
75
  };
76
76
  };
77
+ export declare type Rank = {
78
+ rank: number;
79
+ };
77
80
  export declare type ProgressionAnswerItem = {
78
81
  isCorrect: boolean;
79
82
  slideRef: string;
@@ -0,0 +1,2 @@
1
+ import { Rank } from '../types/common';
2
+ export declare const fetchRank: (token: string) => Promise<Rank>;
@@ -0,0 +1,54 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import crossFetch from 'cross-fetch';
38
+ import decode from 'jwt-decode';
39
+ import { toJSON } from './tools/fetch-responses';
40
+ export var fetchRank = function (token) { return __awaiter(void 0, void 0, void 0, function () {
41
+ var _a, userId, host, response;
42
+ return __generator(this, function (_b) {
43
+ switch (_b.label) {
44
+ case 0:
45
+ _a = decode(token), userId = _a.user, host = _a.host;
46
+ return [4 /*yield*/, crossFetch("".concat(host, "/api/v1/leaderboard/rank/").concat(userId, "?group=ALL"), {
47
+ headers: { authorization: token }
48
+ })];
49
+ case 1:
50
+ response = _b.sent();
51
+ return [2 /*return*/, toJSON(response)];
52
+ }
53
+ });
54
+ }); };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,78 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import test from 'ava';
38
+ import nock from 'nock';
39
+ import { fetchRank } from '../fetch-rank';
40
+ var result = {
41
+ rank: 93
42
+ };
43
+ test.before(function () {
44
+ nock('http://localhost:3000')
45
+ .get('/api/v1/leaderboard/rank/592d830b240b923f00bffba6?group=ALL')
46
+ .reply(200, result);
47
+ });
48
+ test.after(function () {
49
+ nock.cleanAll();
50
+ });
51
+ test('should fetch rank with success', function (t) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var token, rank;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ token = process.env.API_TEST_TOKEN || '';
57
+ return [4 /*yield*/, fetchRank(token)];
58
+ case 1:
59
+ rank = _a.sent();
60
+ t.deepEqual(result, rank);
61
+ return [2 /*return*/];
62
+ }
63
+ });
64
+ }); });
65
+ test('should reject bad token', function (t) { return __awaiter(void 0, void 0, void 0, function () {
66
+ var badToken, error;
67
+ return __generator(this, function (_a) {
68
+ switch (_a.label) {
69
+ case 0:
70
+ badToken = 'token is not a jwt';
71
+ return [4 /*yield*/, t.throwsAsync(function () { return fetchRank(badToken); })];
72
+ case 1:
73
+ error = _a.sent();
74
+ t.is(error === null || error === void 0 ? void 0 : error.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
75
+ return [2 /*return*/];
76
+ }
77
+ });
78
+ }); });
@@ -74,6 +74,9 @@ export declare type SlideFromAPI = {
74
74
  type: 'chapter' | 'course';
75
75
  };
76
76
  };
77
+ export declare type Rank = {
78
+ rank: number;
79
+ };
77
80
  export declare type ProgressionAnswerItem = {
78
81
  isCorrect: boolean;
79
82
  slideRef: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorpacademy/app-review",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=16.15.0"
@@ -41,7 +41,7 @@
41
41
  "./package.json": "./package.json"
42
42
  },
43
43
  "dependencies": {
44
- "@coorpacademy/components": "10.22.20",
44
+ "@coorpacademy/components": "10.22.22",
45
45
  "@coorpacademy/redux-task": "^1.1.5",
46
46
  "cross-fetch": "^3.1.5",
47
47
  "jwt-decode": "^3.1.2",
@@ -78,5 +78,5 @@
78
78
  "ts-node": "^10.9.1",
79
79
  "typescript": "^4.7.4"
80
80
  },
81
- "gitHead": "4b6111dabb768f900ef6d35f16d40844e74336dd"
81
+ "gitHead": "6eca157ba8c342a0d345a7d303166b43e4a9792a"
82
82
  }
@@ -0,0 +1,14 @@
1
+ import crossFetch from 'cross-fetch';
2
+ import decode from 'jwt-decode';
3
+
4
+ import {JWT, Rank} from '../types/common';
5
+ import {toJSON} from './tools/fetch-responses';
6
+
7
+ export const fetchRank = async (token: string): Promise<Rank> => {
8
+ const {user: userId, host}: JWT = decode(token);
9
+ const response = await crossFetch(`${host}/api/v1/leaderboard/rank/${userId}?group=ALL`, {
10
+ headers: {authorization: token}
11
+ });
12
+
13
+ return toJSON<Rank>(response);
14
+ };
@@ -0,0 +1,34 @@
1
+ import test from 'ava';
2
+ import nock from 'nock';
3
+ import {Rank} from '../../types/common';
4
+ import {fetchRank} from '../fetch-rank';
5
+
6
+ const result: Rank = {
7
+ rank: 93
8
+ };
9
+
10
+ test.before(() => {
11
+ nock('http://localhost:3000')
12
+ .get('/api/v1/leaderboard/rank/592d830b240b923f00bffba6?group=ALL')
13
+ .reply(200, result);
14
+ });
15
+
16
+ test.after(() => {
17
+ nock.cleanAll();
18
+ });
19
+
20
+ test('should fetch rank with success', async t => {
21
+ const token = process.env.API_TEST_TOKEN || '';
22
+ const rank = await fetchRank(token);
23
+ t.deepEqual(result, rank);
24
+ });
25
+
26
+ test('should reject bad token', async t => {
27
+ const badToken = 'token is not a jwt';
28
+ const error = await t.throwsAsync(() => fetchRank(badToken));
29
+
30
+ t.is(
31
+ error?.message,
32
+ "Invalid token specified: Cannot read properties of undefined (reading 'replace')"
33
+ );
34
+ });
@@ -90,6 +90,10 @@ export type SlideFromAPI = {
90
90
  };
91
91
  };
92
92
 
93
+ export type Rank = {
94
+ rank: number;
95
+ };
96
+
93
97
  export type ProgressionAnswerItem = {
94
98
  isCorrect: boolean;
95
99
  slideRef: string;