-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(user-preferences): move themes to user preferences
- Loading branch information
1 parent
ba95569
commit 4190e76
Showing
46 changed files
with
490 additions
and
448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createConfigDomainPersistenceService } from "backend/lib/config-persistence"; | ||
|
||
export const setupUserPreferencesTestData = async () => { | ||
const configPersistenceService = | ||
createConfigDomainPersistenceService("users-preferences"); | ||
|
||
await configPersistenceService.resetToEmpty(); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import handler from "pages/api/user-preferences/[key]"; | ||
import { | ||
createAuthenticatedMocks, | ||
setupAllTestData, | ||
} from "__tests__/api/_test-utils"; | ||
|
||
describe("/api/user-preferences/[key]", () => { | ||
beforeAll(async () => { | ||
await setupAllTestData(["users-preferences"]); | ||
}); | ||
|
||
it("should get the default value when value doesn't exist for user", async () => { | ||
const getRequest = createAuthenticatedMocks({ | ||
method: "GET", | ||
query: { | ||
key: "theme", | ||
}, | ||
}); | ||
|
||
await handler(getRequest.req, getRequest.res); | ||
|
||
expect(getRequest.res._getJSONData()).toMatchInlineSnapshot(` | ||
{ | ||
"data": "light", | ||
} | ||
`); | ||
}); | ||
|
||
it("should create authenticated user preference when doesn't exist", async () => { | ||
const postRequest = createAuthenticatedMocks({ | ||
method: "PUT", | ||
query: { | ||
key: "theme", | ||
}, | ||
body: { | ||
data: "dark", | ||
}, | ||
}); | ||
|
||
await handler(postRequest.req, postRequest.res); | ||
|
||
expect(postRequest.res._getStatusCode()).toBe(204); | ||
|
||
const getRequest = createAuthenticatedMocks({ | ||
method: "GET", | ||
query: { | ||
key: "theme", | ||
}, | ||
}); | ||
|
||
await handler(getRequest.req, getRequest.res); | ||
|
||
expect(getRequest.res._getJSONData()).toMatchInlineSnapshot(` | ||
{ | ||
"data": "dark", | ||
} | ||
`); | ||
}); | ||
|
||
it("should update authenticated user preference it when exists", async () => { | ||
const postRequest = createAuthenticatedMocks({ | ||
method: "PUT", | ||
query: { | ||
key: "theme", | ||
}, | ||
body: { | ||
data: "light", | ||
}, | ||
}); | ||
|
||
await handler(postRequest.req, postRequest.res); | ||
|
||
const getRequest = createAuthenticatedMocks({ | ||
method: "GET", | ||
query: { | ||
key: "theme", | ||
}, | ||
}); | ||
|
||
await handler(getRequest.req, getRequest.res); | ||
|
||
expect(getRequest.res._getJSONData()).toMatchInlineSnapshot(` | ||
{ | ||
"data": "light", | ||
} | ||
`); | ||
}); | ||
|
||
describe("Preference key validation", () => { | ||
it("GET", async () => { | ||
const getRequest = createAuthenticatedMocks({ | ||
method: "GET", | ||
query: { | ||
key: "some-invalid-preference-key", | ||
}, | ||
}); | ||
|
||
await handler(getRequest.req, getRequest.res); | ||
|
||
expect(getRequest.res._getStatusCode()).toBe(400); | ||
|
||
expect(getRequest.res._getJSONData()).toMatchInlineSnapshot(` | ||
{ | ||
"message": "User Preference key 'some-invalid-preference-key' doesn't exist", | ||
"method": "GET", | ||
"name": "BadRequestError", | ||
"path": "", | ||
"statusCode": 400, | ||
} | ||
`); | ||
}); | ||
|
||
it("PUT", async () => { | ||
const getRequest = createAuthenticatedMocks({ | ||
query: { | ||
key: "some-invalid-preference-key", | ||
}, | ||
method: "PUT", | ||
body: { | ||
data: "light", | ||
}, | ||
}); | ||
|
||
await handler(getRequest.req, getRequest.res); | ||
|
||
expect(getRequest.res._getStatusCode()).toBe(400); | ||
|
||
expect(getRequest.res._getJSONData()).toMatchInlineSnapshot(` | ||
{ | ||
"message": "User Preference key 'some-invalid-preference-key' doesn't exist", | ||
"method": "PUT", | ||
"name": "BadRequestError", | ||
"path": "", | ||
"statusCode": 400, | ||
} | ||
`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.