@instructure/platform-mock-canvas-api 0.5.1 → 0.6.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../src/handlers/modules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAmDzC,2EAA2E;AAC3E,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAgCD;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CAQR;AASD,eAAO,MAAM,cAAc,EAAE,cAAc,EAuC1C,CAAA"}
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../src/handlers/modules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAmDzC,2EAA2E;AAC3E,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAgCD;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CAQR;AASD,eAAO,MAAM,cAAc,EAAE,cAAc,EAqE1C,CAAA"}
package/dist/index.js CHANGED
@@ -1,87 +1,103 @@
1
- import { courses as I, educatorAccessibilityCourseStatistics as _, moduleScenariosByCourseId as S, submissionsStore as m } from "./fixtures.js";
2
- import { MODULES_SMALL_MODULE_COUNT as F, MODULE_ITEMS_INLINE_LIMIT as R, buildCanvasCourseModules as O, mockEducatorAccessibilityStatistic as B, modulesCourseEmpty as G, modulesCourseFatModule as $, modulesCourseLarge as K, modulesCourseSmall as X, stickerDescriptions as Y, stickerTranslations as q, submissions as z } from "./fixtures.js";
3
- import { http as u, HttpResponse as r } from "msw";
4
- const j = [
1
+ import { courses as b, educatorAccessibilityCourseStatistics as _, moduleScenariosByCourseId as j, submissionsStore as m } from "./fixtures.js";
2
+ import { MODULES_SMALL_MODULE_COUNT as D, MODULE_ITEMS_INLINE_LIMIT as F, buildCanvasCourseModules as O, mockEducatorAccessibilityStatistic as B, modulesCourseEmpty as G, modulesCourseFatModule as $, modulesCourseLarge as K, modulesCourseSmall as X, stickerDescriptions as Y, stickerTranslations as q, submissions as z } from "./fixtures.js";
3
+ import { http as u, HttpResponse as t } from "msw";
4
+ const S = [
5
5
  // GET /api/v1/courses
6
- u.get("/api/v1/courses", () => r.json(I)),
6
+ u.get("/api/v1/courses", () => t.json(b)),
7
7
  // GET /api/v1/courses/:courseId (courseId may be a numeric id or a `uuid:<uuid>` ref)
8
8
  u.get("/api/v1/courses/:courseId", ({ params: e }) => {
9
- const s = String(e.courseId).replace(/^uuid:/, ""), n = I.find((t) => t.id === s || t.uuid === s);
10
- return n ? r.json(n) : r.json({ errors: [{ message: "Course not found" }] }, { status: 404 });
9
+ const s = String(e.courseId).replace(/^uuid:/, ""), n = b.find((o) => o.id === s || o.uuid === s);
10
+ return n ? t.json(n) : t.json({ errors: [{ message: "Course not found" }] }, { status: 404 });
11
11
  })
12
12
  ], P = [
13
- u.get("/api/v1/users/:userId/educator_accessibility_course_statistics", () => r.json(_))
14
- ], M = 10, k = 100, l = () => r.json(
13
+ u.get("/api/v1/users/:userId/educator_accessibility_course_statistics", () => t.json(_))
14
+ ], M = 10, L = 100, d = () => t.json(
15
15
  { errors: [{ message: "The specified resource does not exist." }] },
16
16
  {
17
17
  status: 404
18
18
  }
19
- ), g = /* @__PURE__ */ new Map(), b = (e) => {
19
+ ), g = /* @__PURE__ */ new Map(), p = (e) => {
20
20
  const s = g.get(e);
21
21
  if (s) return s;
22
- const n = S[e];
22
+ const n = j[e];
23
23
  if (!n) return;
24
- const t = n();
25
- return g.set(e, t), t;
24
+ const o = n();
25
+ return g.set(e, o), o;
26
26
  };
27
- function H() {
27
+ function x() {
28
28
  g.clear();
29
29
  }
30
30
  const f = (e) => {
31
31
  const s = Number.parseInt(e.searchParams.get("per_page") ?? "", 10), n = Number.parseInt(e.searchParams.get("page") ?? "", 10);
32
32
  return {
33
- perPage: Number.isFinite(s) && s > 0 ? Math.min(s, k) : M,
33
+ perPage: Number.isFinite(s) && s > 0 ? Math.min(s, L) : M,
34
34
  page: Number.isFinite(n) && n > 0 ? n : 1
35
35
  };
36
- }, v = (e) => [...e.searchParams.getAll("include[]"), ...e.searchParams.getAll("include")].flatMap(
36
+ }, k = (e) => [...e.searchParams.getAll("include[]"), ...e.searchParams.getAll("include")].flatMap(
37
37
  (s) => s.split(",")
38
- ), y = (e, s, n) => {
39
- const t = new URL(e.href);
40
- return t.searchParams.set("page", String(s)), t.searchParams.set("per_page", String(n)), t.href;
38
+ ), v = (e, s, n) => {
39
+ const o = new URL(e.href);
40
+ return o.searchParams.set("page", String(s)), o.searchParams.set("per_page", String(n)), o.href;
41
41
  };
42
- function h(e, s, n, t) {
43
- const o = Math.max(1, Math.ceil(t / n)), i = [["current", s]];
44
- return s < o && i.push(["next", s + 1]), s > 1 && i.push(["prev", s - 1]), i.push(["first", 1], ["last", o]), i.map(([a, c]) => `<${y(e, c, n)}>; rel="${a}"`).join(",");
42
+ function h(e, s, n, o) {
43
+ const r = Math.max(1, Math.ceil(o / n)), i = [["current", s]];
44
+ return s < r && i.push(["next", s + 1]), s > 1 && i.push(["prev", s - 1]), i.push(["first", 1], ["last", r]), i.map(([c, a]) => `<${v(e, a, n)}>; rel="${c}"`).join(",");
45
45
  }
46
- const L = (e) => {
46
+ const y = (e) => {
47
47
  const s = { ...e };
48
48
  return delete s.items, s;
49
- }, A = [
49
+ }, w = [
50
50
  // GET /api/v1/courses/:courseId/modules
51
51
  u.get("/api/v1/courses/:courseId/modules", ({ params: e, request: s }) => {
52
- const n = b(String(e.courseId));
53
- if (!n) return l();
54
- const t = new URL(s.url), { page: o, perPage: i } = f(t), a = v(t).includes("items"), c = (o - 1) * i, d = n.modules.slice(c, c + i).map((p) => a ? p : L(p));
55
- return r.json(d, {
56
- headers: { Link: h(t, o, i, n.modules.length) }
52
+ const n = p(String(e.courseId));
53
+ if (!n) return d();
54
+ const o = new URL(s.url), { page: r, perPage: i } = f(o), c = k(o).includes("items"), a = (r - 1) * i, l = n.modules.slice(a, a + i).map((I) => c ? I : y(I));
55
+ return t.json(l, {
56
+ headers: { Link: h(o, r, i, n.modules.length) }
57
57
  });
58
58
  }),
59
59
  // GET /api/v1/courses/:courseId/modules/:moduleId/items
60
60
  u.get("/api/v1/courses/:courseId/modules/:moduleId/items", ({ params: e, request: s }) => {
61
- const n = b(String(e.courseId));
62
- if (!n) return l();
63
- const t = String(e.moduleId), o = n.itemsByModuleId[t];
64
- if (!o) return l();
65
- const i = new URL(s.url), { page: a, perPage: c } = f(i), d = (a - 1) * c;
66
- return r.json(o.slice(d, d + c), {
67
- headers: { Link: h(i, a, c, o.length) }
61
+ const n = p(String(e.courseId));
62
+ if (!n) return d();
63
+ const o = String(e.moduleId), r = n.itemsByModuleId[o];
64
+ if (!r) return d();
65
+ const i = new URL(s.url), { page: c, perPage: a } = f(i), l = (c - 1) * a;
66
+ return t.json(r.slice(l, l + a), {
67
+ headers: { Link: h(i, c, a, r.length) }
68
68
  });
69
- })
70
- ], C = 300, E = [
69
+ }),
70
+ // POST /courses/:courseId/modules/:moduleId/collapse
71
+ //
72
+ // Mirrors `ContextModulesController#toggle_collapse`: collapsing returns the
73
+ // progression, uncollapsing returns the module's content tags.
74
+ u.post("/courses/:courseId/modules/:moduleId/collapse", async ({ params: e, request: s }) => {
75
+ const n = p(String(e.courseId));
76
+ if (!n) return d();
77
+ const o = Number(e.moduleId);
78
+ if (!n.modules.some((c) => c.id === o)) return d();
79
+ const r = await s.json().catch(() => null), i = !!(r != null && r.collapse);
80
+ return t.json(i ? { collapsed: !0 } : []);
81
+ }),
82
+ // POST /courses/:courseId/collapse_all_modules
83
+ //
84
+ // Mirrors `ContextModulesController#toggle_collapse_all`.
85
+ u.post("/courses/:courseId/collapse_all_modules", ({ params: e, request: s }) => !p(String(e.courseId)) || !new URL(s.url).searchParams.has("collapse") ? d() : t.json({}))
86
+ ], A = 300, C = [
71
87
  // GET submission
72
88
  u.get(
73
89
  "/api/v1/courses/:courseId/assignments/:assignmentId/submissions/:submissionId",
74
90
  ({ params: e }) => {
75
91
  const s = m.get(e.submissionId);
76
- return s ? r.json(s) : r.json({ errors: [{ message: "Submission not found" }] }, { status: 404 });
92
+ return s ? t.json(s) : t.json({ errors: [{ message: "Submission not found" }] }, { status: 404 });
77
93
  }
78
94
  ),
79
95
  // PATCH submission (update sticker)
80
96
  u.patch(
81
97
  "/api/v1/courses/:courseId/assignments/:assignmentId/submissions/:submissionId",
82
98
  async ({ params: e, request: s }) => {
83
- const { submissionId: n } = e, t = await s.json(), o = m.get(n);
84
- return o ? (t.submission && "sticker" in t.submission && t.submission.sticker !== void 0 && (o.sticker = t.submission.sticker, m.set(n, o)), await new Promise((i) => setTimeout(i, C)), r.json(o)) : r.json({ errors: [{ message: "Submission not found" }] }, { status: 404 });
99
+ const { submissionId: n } = e, o = await s.json(), r = m.get(n);
100
+ return r ? (o.submission && "sticker" in o.submission && o.submission.sticker !== void 0 && (r.sticker = o.submission.sticker, m.set(n, r)), await new Promise((i) => setTimeout(i, A)), t.json(r)) : t.json({ errors: [{ message: "Submission not found" }] }, { status: 404 });
85
101
  }
86
102
  ),
87
103
  // GET all submissions for an assignment
@@ -89,50 +105,50 @@ const L = (e) => {
89
105
  const s = Array.from(m.values()).filter(
90
106
  (n) => n.course_id === e.courseId && n.assignment_id === e.assignmentId
91
107
  );
92
- return r.json(s);
108
+ return t.json(s);
93
109
  })
94
- ], w = [
110
+ ], E = [
95
111
  // PUT /api/v1/users/:userId/colors/:assetString -> persist a course color
96
112
  u.put("/api/v1/users/:userId/colors/:assetString", async ({ request: e }) => {
97
113
  const s = await e.json().catch(() => ({}));
98
- return r.json({ hexcode: s.hexcode ?? "" });
114
+ return t.json({ hexcode: s.hexcode ?? "" });
99
115
  }),
100
116
  // PUT /api/v1/users/self/course_nicknames/:courseId -> set a nickname
101
117
  u.put("/api/v1/users/self/course_nicknames/:courseId", async ({ request: e }) => {
102
118
  const s = await e.json().catch(() => ({}));
103
- return r.json({ nickname: s.nickname ?? "", name: s.nickname ?? "" });
119
+ return t.json({ nickname: s.nickname ?? "", name: s.nickname ?? "" });
104
120
  }),
105
121
  // DELETE /api/v1/users/self/course_nicknames/:courseId -> clear a nickname
106
- u.delete("/api/v1/users/self/course_nicknames/:courseId", () => r.json({ nickname: null, name: "" }))
107
- ], N = [
108
- ...j,
122
+ u.delete("/api/v1/users/self/course_nicknames/:courseId", () => t.json({ nickname: null, name: "" }))
123
+ ], H = [
124
+ ...S,
109
125
  ...P,
110
- ...A,
111
- ...E,
112
- ...w
126
+ ...w,
127
+ ...C,
128
+ ...E
113
129
  ];
114
130
  export {
115
- F as MODULES_SMALL_MODULE_COUNT,
116
- R as MODULE_ITEMS_INLINE_LIMIT,
131
+ D as MODULES_SMALL_MODULE_COUNT,
132
+ F as MODULE_ITEMS_INLINE_LIMIT,
117
133
  O as buildCanvasCourseModules,
118
134
  h as buildLinkHeader,
119
- j as courseHandlers,
120
- I as courses,
135
+ S as courseHandlers,
136
+ b as courses,
121
137
  _ as educatorAccessibilityCourseStatistics,
122
138
  P as educatorAccessibilityHandlers,
123
- N as handlers,
139
+ H as handlers,
124
140
  B as mockEducatorAccessibilityStatistic,
125
- A as moduleHandlers,
126
- S as moduleScenariosByCourseId,
141
+ w as moduleHandlers,
142
+ j as moduleScenariosByCourseId,
127
143
  G as modulesCourseEmpty,
128
144
  $ as modulesCourseFatModule,
129
145
  K as modulesCourseLarge,
130
146
  X as modulesCourseSmall,
131
- H as resetModuleScenarios,
147
+ x as resetModuleScenarios,
132
148
  Y as stickerDescriptions,
133
149
  q as stickerTranslations,
134
- E as submissionHandlers,
150
+ C as submissionHandlers,
135
151
  z as submissions,
136
152
  m as submissionsStore,
137
- w as userColorHandlers
153
+ E as userColorHandlers
138
154
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/platform-mock-canvas-api",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",