@truedat/auth 4.44.5 → 4.45.4

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.45.4] 2022-06-03
4
+
5
+ ### Changed
6
+
7
+ - Removed password and rep_password field from UserForm user update to avoid 403 error
8
+
3
9
  ## [4.44.4] 2022-05-19
4
10
 
5
11
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/auth",
3
- "version": "4.44.5",
3
+ "version": "4.45.4",
4
4
  "description": "Truedat Web Auth",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -34,7 +34,7 @@
34
34
  "@testing-library/jest-dom": "^5.16.4",
35
35
  "@testing-library/react": "^12.0.0",
36
36
  "@testing-library/user-event": "^13.2.1",
37
- "@truedat/test": "4.44.5",
37
+ "@truedat/test": "4.45.1",
38
38
  "babel-jest": "^28.1.0",
39
39
  "babel-plugin-dynamic-import-node": "^2.3.3",
40
40
  "babel-plugin-lodash": "^3.3.4",
@@ -87,7 +87,7 @@
87
87
  ]
88
88
  },
89
89
  "dependencies": {
90
- "@truedat/core": "4.44.5",
90
+ "@truedat/core": "4.45.1",
91
91
  "auth0-js": "^9.12.2",
92
92
  "immutable": "^4.0.0-rc.12",
93
93
  "jwt-decode": "^2.2.0",
@@ -109,5 +109,5 @@
109
109
  "react-dom": ">= 16.8.6 < 17",
110
110
  "semantic-ui-react": ">= 0.88.2 < 2.1"
111
111
  },
112
- "gitHead": "5a339468198c803592b285eddd0dd0c0b0eced93"
112
+ "gitHead": "40ec430c50a2da5eca991e9b946e8e47ffe1e477"
113
113
  }
@@ -126,7 +126,21 @@ export const UserForm = ({ isSubmitting, onSubmit, user, groups }) => {
126
126
  rep_password: "",
127
127
  ...user,
128
128
  },
129
+ /*
130
+ * Remove PasswordFormFields' inputs (password, rep_password) if it is not
131
+ * mounted (user update). Keep them if it is mounted (user creation).
132
+ * Otherwise, td-auth returns forbidden because password updates are handled
133
+ * in the Password form, using /api/password, not in this UserForm that
134
+ * PUTs to /api/users/<user_id>
135
+ * https://stackoverflow.com/q/70105636
136
+ * This was not needed in v6, but it is in v7:
137
+ * https://react-hook-form.com/migrate-v6-to-v7/
138
+ * Important: input value and reference will no longer get removed after
139
+ * unmount unless shouldUnregister is true.
140
+ */
141
+ shouldUnregister: true,
129
142
  });
143
+
130
144
  const { errors, isDirty, isValid } = formState;
131
145
  return (
132
146
  <Form onSubmit={handleSubmit(onSubmit)}>
@@ -0,0 +1,96 @@
1
+ import { testSaga } from "redux-saga-test-plan";
2
+ import { apiJsonPut, JSON_OPTS } from "@truedat/core/services/api";
3
+ import { takeLatest } from "redux-saga/effects";
4
+ import {
5
+ updateUserRequestSaga,
6
+ updateUserSaga,
7
+ updatePasswordSaga,
8
+ } from "../updateUser";
9
+ import { updateUser, updatePassword } from "../../routines";
10
+ import { API_USER } from "../../api";
11
+
12
+ describe("sagas: updateUserRequestSaga", () => {
13
+ it("should invoke updateUserSaga on updateUser.TRIGGER", () => {
14
+ expect(() => {
15
+ testSaga(updateUserRequestSaga)
16
+ .next()
17
+ .all([
18
+ takeLatest(updateUser.TRIGGER, updateUserSaga),
19
+ takeLatest(updatePassword.TRIGGER, updatePasswordSaga),
20
+ ])
21
+ .finish()
22
+ .isDone();
23
+ }).not.toThrow();
24
+ });
25
+
26
+ it("should throw exception if an unhandled action is received", () => {
27
+ expect(() => {
28
+ testSaga(updateUserRequestSaga)
29
+ .next()
30
+ .takeLatest("FOO", updateUserRequestSaga);
31
+ }).toThrow();
32
+ });
33
+ });
34
+
35
+ describe("sagas: updateUserSaga", () => {
36
+ const userId = 1;
37
+ const user = {
38
+ id: userId,
39
+ user_name: "uname",
40
+ email: "email@email.com",
41
+ full_name: "User Full Name",
42
+ groups: "[]",
43
+ role: "admin",
44
+ };
45
+ const payload = {
46
+ user,
47
+ };
48
+ const request_data = {
49
+ user,
50
+ };
51
+
52
+ it("should put a success action when a response is returned", () => {
53
+ expect(() => {
54
+ testSaga(updateUserSaga, { payload: user })
55
+ .next()
56
+ .put({ ...updateUser.request() })
57
+ .next()
58
+ .call(
59
+ apiJsonPut,
60
+ API_USER.replace(":id", userId),
61
+ request_data,
62
+ JSON_OPTS
63
+ )
64
+ .next({ data: payload })
65
+ .put({ ...updateUser.success(payload) })
66
+ .next()
67
+ .put(updateUser.fulfill())
68
+ .next()
69
+ .isDone();
70
+ }).not.toThrow();
71
+ });
72
+
73
+ it("should put a failure action when the call returns an error", () => {
74
+ const message = "Request failed";
75
+ const error = { message };
76
+
77
+ expect(() => {
78
+ testSaga(updateUserSaga, { payload: user })
79
+ .next()
80
+ .put({ ...updateUser.request() })
81
+ .next()
82
+ .call(
83
+ apiJsonPut,
84
+ API_USER.replace(":id", userId),
85
+ request_data,
86
+ JSON_OPTS
87
+ )
88
+ .throw(error)
89
+ .put(updateUser.failure(message))
90
+ .next()
91
+ .put(updateUser.fulfill())
92
+ .next()
93
+ .isDone();
94
+ }).not.toThrow();
95
+ });
96
+ });
@@ -39,6 +39,6 @@ export function* updatePasswordSaga({ payload }) {
39
39
  export function* updateUserRequestSaga() {
40
40
  yield all([
41
41
  takeLatest(updateUser.TRIGGER, updateUserSaga),
42
- takeLatest(updatePassword.TRIGGER, updatePasswordSaga)
42
+ takeLatest(updatePassword.TRIGGER, updatePasswordSaga),
43
43
  ]);
44
44
  }