Skip to content

Commit

Permalink
Allow to reconfigure server credentials via ENV variables (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianruesch authored Dec 10, 2023
1 parent 0f49163 commit 0a53975
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ VITE_CLIENT_ID=
VITE_CLIENT_SECRET=
VITE_REDIRECT_URI=



# JIRA SERVER CREDENTIALS
VITE_JIRA_SERVER_DEFAULT_URL=
VITE_JIRA_SERVER_DEFAULT_USERNAME=
VITE_JIRA_SERVER_DEFAULT_PASSWORD=
3 changes: 3 additions & 0 deletions src/components/Login/Login.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { render, screen } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { Login } from "./Login"

jest.mock("../../get-meta-env.ts", () => ({
getImportMetaEnv: jest.fn(() => ({})),
}))
jest.mock("./jira-cloud/loginToJiraCloud.ts", () => ({
loginToJiraCloud: jest.fn(),
}))
Expand Down
8 changes: 5 additions & 3 deletions src/components/Login/jira-server/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useForm } from "@mantine/form"
import { useTranslation } from "react-i18next"
import { LoginFormValues } from "./LoginFormValues"
import { loginToJiraServer } from "./loginToJiraServer"
import { getImportMetaEnv } from "../../../get-meta-env";

export function LoginForm({
goBack,
Expand All @@ -12,11 +13,12 @@ export function LoginForm({
onSuccess: () => void
}) {
const { t } = useTranslation("login")
const metaEnv = getImportMetaEnv()
const form = useForm<LoginFormValues>({
initialValues: {
url: "http://localhost:8080",
username: "admin",
password: "admin",
url: metaEnv.VITE_JIRA_SERVER_DEFAULT_URL ?? '',
username: metaEnv.VITE_JIRA_SERVER_DEFAULT_USERNAME ?? '',
password: metaEnv.VITE_JIRA_SERVER_DEFAULT_PASSWORD ?? '',
},
})
return (
Expand Down
5 changes: 5 additions & 0 deletions src/get-meta-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function getImportMetaEnv() {
// Import meta has its own function to allow testing components using the import meta, as it may not be available in
// test environments and should be mocked anyway.
return import.meta.env
}

0 comments on commit 0a53975

Please sign in to comment.