Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to reconfigure server credentials via ENV variables #88

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}