@instructure/platform-mock-canvas-api 0.2.0 → 0.3.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,6 +1,7 @@
1
1
  import { RequestHandler } from 'msw';
2
2
  import { courseHandlers } from './courses';
3
3
  import { submissionHandlers } from './submissions';
4
+ import { userColorHandlers } from './userColors';
4
5
  export declare const handlers: RequestHandler[];
5
- export { courseHandlers, submissionHandlers };
6
+ export { courseHandlers, submissionHandlers, userColorHandlers };
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD,eAAO,MAAM,QAAQ,EAAE,cAAc,EAA+C,CAAA;AAEpF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,eAAO,MAAM,QAAQ,EAAE,cAAc,EAIpC,CAAA;AAED,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { RequestHandler } from 'msw';
2
+ /**
3
+ * Handlers for the user course-color and course-nickname endpoints used by the
4
+ * platform-color-picker. Echo the submitted values back, matching Canvas shape.
5
+ */
6
+ export declare const userColorHandlers: RequestHandler[];
7
+ //# sourceMappingURL=userColors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userColors.d.ts","sourceRoot":"","sources":["../../src/handlers/userColors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAGzC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,cAAc,EAiB7C,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './fixtures';
2
- export { courseHandlers, handlers, submissionHandlers } from './handlers';
2
+ export { courseHandlers, handlers, submissionHandlers, userColorHandlers } from './handlers';
3
3
  export type * from './types';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACzE,mBAAmB,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC5F,mBAAmB,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -1,46 +1,64 @@
1
- import { courses as m, submissionsStore as u } from "./fixtures.js";
2
- import { stickerDescriptions as l, stickerTranslations as v, submissions as k } from "./fixtures.js";
3
- import { http as r, HttpResponse as i } from "msw";
4
- const a = [
1
+ import { courses as c, submissionsStore as u } from "./fixtures.js";
2
+ import { stickerDescriptions as k, stickerTranslations as v, submissions as h } from "./fixtures.js";
3
+ import { http as i, HttpResponse as e } from "msw";
4
+ const m = [
5
5
  // GET /api/v1/courses
6
- r.get("/api/v1/courses", () => i.json(m)),
6
+ i.get("/api/v1/courses", () => e.json(c)),
7
7
  // GET /api/v1/courses/:courseId (courseId may be a numeric id or a `uuid:<uuid>` ref)
8
- r.get("/api/v1/courses/:courseId", ({ params: n }) => {
9
- const s = String(n.courseId).replace(/^uuid:/, ""), o = m.find((e) => e.id === s || e.uuid === s);
10
- return o ? i.json(o) : i.json({ errors: [{ message: "Course not found" }] }, { status: 404 });
8
+ i.get("/api/v1/courses/:courseId", ({ params: n }) => {
9
+ const s = String(n.courseId).replace(/^uuid:/, ""), o = c.find((r) => r.id === s || r.uuid === s);
10
+ return o ? e.json(o) : e.json({ errors: [{ message: "Course not found" }] }, { status: 404 });
11
11
  })
12
12
  ], d = 300, b = [
13
13
  // GET submission
14
- r.get(
14
+ i.get(
15
15
  "/api/v1/courses/:courseId/assignments/:assignmentId/submissions/:submissionId",
16
16
  ({ params: n }) => {
17
17
  const s = u.get(n.submissionId);
18
- return s ? i.json(s) : i.json({ errors: [{ message: "Submission not found" }] }, { status: 404 });
18
+ return s ? e.json(s) : e.json({ errors: [{ message: "Submission not found" }] }, { status: 404 });
19
19
  }
20
20
  ),
21
21
  // PATCH submission (update sticker)
22
- r.patch(
22
+ i.patch(
23
23
  "/api/v1/courses/:courseId/assignments/:assignmentId/submissions/:submissionId",
24
24
  async ({ params: n, request: s }) => {
25
- const { submissionId: o } = n, e = await s.json(), t = u.get(o);
26
- return t ? (e.submission && "sticker" in e.submission && e.submission.sticker !== void 0 && (t.sticker = e.submission.sticker, u.set(o, t)), await new Promise((c) => setTimeout(c, d)), i.json(t)) : i.json({ errors: [{ message: "Submission not found" }] }, { status: 404 });
25
+ const { submissionId: o } = n, r = await s.json(), t = u.get(o);
26
+ return t ? (r.submission && "sticker" in r.submission && r.submission.sticker !== void 0 && (t.sticker = r.submission.sticker, u.set(o, t)), await new Promise((a) => setTimeout(a, d)), e.json(t)) : e.json({ errors: [{ message: "Submission not found" }] }, { status: 404 });
27
27
  }
28
28
  ),
29
29
  // GET all submissions for an assignment
30
- r.get("/api/v1/courses/:courseId/assignments/:assignmentId/submissions", ({ params: n }) => {
30
+ i.get("/api/v1/courses/:courseId/assignments/:assignmentId/submissions", ({ params: n }) => {
31
31
  const s = Array.from(u.values()).filter(
32
32
  (o) => o.course_id === n.courseId && o.assignment_id === n.assignmentId
33
33
  );
34
- return i.json(s);
34
+ return e.json(s);
35
35
  })
36
- ], f = [...a, ...b];
36
+ ], g = [
37
+ // PUT /api/v1/users/:userId/colors/:assetString -> persist a course color
38
+ i.put("/api/v1/users/:userId/colors/:assetString", async ({ request: n }) => {
39
+ const s = await n.json().catch(() => ({}));
40
+ return e.json({ hexcode: s.hexcode ?? "" });
41
+ }),
42
+ // PUT /api/v1/users/self/course_nicknames/:courseId -> set a nickname
43
+ i.put("/api/v1/users/self/course_nicknames/:courseId", async ({ request: n }) => {
44
+ const s = await n.json().catch(() => ({}));
45
+ return e.json({ nickname: s.nickname ?? "", name: s.nickname ?? "" });
46
+ }),
47
+ // DELETE /api/v1/users/self/course_nicknames/:courseId -> clear a nickname
48
+ i.delete("/api/v1/users/self/course_nicknames/:courseId", () => e.json({ nickname: null, name: "" }))
49
+ ], f = [
50
+ ...m,
51
+ ...b,
52
+ ...g
53
+ ];
37
54
  export {
38
- a as courseHandlers,
39
- m as courses,
55
+ m as courseHandlers,
56
+ c as courses,
40
57
  f as handlers,
41
- l as stickerDescriptions,
58
+ k as stickerDescriptions,
42
59
  v as stickerTranslations,
43
60
  b as submissionHandlers,
44
- k as submissions,
45
- u as submissionsStore
61
+ h as submissions,
62
+ u as submissionsStore,
63
+ g as userColorHandlers
46
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/platform-mock-canvas-api",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",