Skip to content

Commit 90027a1

Browse files
authored
Update retrieve user api to be versioned (#3102)
1 parent 62483cf commit 90027a1

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

frontend/public/src/containers/App_test.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ describe("Top-level App", () => {
4545
const { inner } = await renderPage()
4646

4747
assert.notExists(inner.find(".app").prop("children"))
48-
sinon.assert.calledWith(helper.handleRequestStub, "/api/users/me", "GET")
48+
sinon.assert.calledWith(
49+
helper.handleRequestStub,
50+
"/api/v0/users/current_user/",
51+
"GET"
52+
)
4953
})
5054

5155
it("fetches user data on load and renders user in the header", async () => {
@@ -65,7 +69,11 @@ describe("Top-level App", () => {
6569
const { inner } = await renderPage()
6670
// So we look to be sure the next child is there, which is <Header />, which is not there otherwise
6771
assert.exists(inner.find("Header"))
68-
sinon.assert.calledWith(helper.handleRequestStub, "/api/users/me", "GET")
72+
sinon.assert.calledWith(
73+
helper.handleRequestStub,
74+
"/api/v0/users/current_user/",
75+
"GET"
76+
)
6977
})
7078

7179
it("adds a user notification if a stored message is found in cookies", async () => {
@@ -104,7 +112,11 @@ describe("Top-level App", () => {
104112
})
105113
await renderPage()
106114
// Should call /api/users/me to get user data
107-
sinon.assert.calledWith(helper.handleRequestStub, "/api/users/me", "GET")
115+
sinon.assert.calledWith(
116+
helper.handleRequestStub,
117+
"/api/v0/users/current_user/",
118+
"GET"
119+
)
108120
// Should NOT call the cart items count API for unauthenticated users
109121
sinon.assert.neverCalledWith(
110122
helper.handleRequestStub,

frontend/public/src/containers/HeaderApp_test.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,22 @@ describe("Top-level HeaderApp", () => {
5252
inner.update()
5353
// So we look to be sure the next child is there, which is <Header />
5454
assert.exists(inner.find("Header"))
55-
sinon.assert.calledWith(helper.handleRequestStub, "/api/users/me", "GET")
55+
sinon.assert.calledWith(
56+
helper.handleRequestStub,
57+
"/api/v0/users/current_user/",
58+
"GET"
59+
)
5660
})
5761

5862
it("tries to fetch user data and no response or an incorrect response renders nothing", async () => {
5963
helper.handleRequestStub.returns({})
6064
const { inner } = await renderPage()
6165
assert.notExists(inner.find("div").prop("children"))
62-
sinon.assert.calledWith(helper.handleRequestStub, "/api/users/me", "GET")
66+
sinon.assert.calledWith(
67+
helper.handleRequestStub,
68+
"/api/v0/users/current_user/",
69+
"GET"
70+
)
6371
})
6472

6573
it("adds a user notification if a stored message is found in cookies", async () => {
@@ -98,7 +106,11 @@ describe("Top-level HeaderApp", () => {
98106
})
99107
await renderPage()
100108
// Should call /api/users/me to get user data
101-
sinon.assert.calledWith(helper.handleRequestStub, "/api/users/me", "GET")
109+
sinon.assert.calledWith(
110+
helper.handleRequestStub,
111+
"/api/v0/users/current_user/",
112+
"GET"
113+
)
102114
// Should NOT call the cart items count API for unauthenticated users
103115
sinon.assert.neverCalledWith(
104116
helper.handleRequestStub,

frontend/public/src/containers/pages/profile/EditProfilePage_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("EditProfilePage", () => {
6262
await inner.find("EditProfileForm").prop("onSubmit")(values, actions)
6363
sinon.assert.calledWith(
6464
helper.handleRequestStub,
65-
"/api/users/me",
65+
"/api/v0/users/me",
6666
"PATCH",
6767
{
6868
body: values,

frontend/public/src/lib/queries/users.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const DEFAULT_OPTIONS = {
3131

3232
export default {
3333
currentUserQuery: () => ({
34-
url: "/api/users/me",
34+
url: "/api/v0/users/current_user/",
3535
transform: transformCurrentUser,
3636
update: updateResult
3737
}),
@@ -48,7 +48,7 @@ export default {
4848
...DEFAULT_OPTIONS,
4949
transform: transformCurrentUser,
5050
update: updateResult,
51-
url: "/api/users/me",
51+
url: "/api/v0/users/me",
5252
body: {
5353
...profileData
5454
}
@@ -57,7 +57,7 @@ export default {
5757
...DEFAULT_OPTIONS,
5858
transform: transformCurrentUser,
5959
update: updateResult,
60-
url: "/api/users/current_user",
60+
url: "/api/v0/users/current_user",
6161
body: {
6262
...profileData
6363
}

users/urls.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@
2424
router.register(r"user_search", UsersViewSet, basename="users_search_api")
2525

2626
urlpatterns = [
27-
path(
28-
"api/users/me",
29-
CurrentUserRetrieveUpdateViewSet.as_view(
30-
{"patch": "update", "get": "retrieve"}
31-
),
32-
name="users_api-me",
33-
),
34-
path(
35-
"api/users/current_user/",
36-
NewCurrentUserRetrieveUpdateViewSet.as_view(
37-
{"patch": "update", "get": "retrieve"}
38-
),
39-
name="users_api-current_user",
40-
),
4127
path("api/", include(router.urls)),
4228
path(
4329
"api/v0/users/me",

0 commit comments

Comments
 (0)