-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($env): additional environments - API integration (#8424)
Make API calls from "order environments" dialog, improve validation
- Loading branch information
Showing
6 changed files
with
145 additions
and
22 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
.../src/component/environments/EnvironmentTable/OrderEnvironments/OrderEnvironments.test.tsx
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,42 @@ | ||
import { screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { OrderEnvironments } from './OrderEnvironments'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupServerRoutes = (changeRequestsEnabled = true) => { | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
environment: 'Pro', | ||
flags: { | ||
purchaseAdditionalEnvironments: true, | ||
}, | ||
}); | ||
}; | ||
|
||
describe('OrderEnvironmentsDialog Component', () => { | ||
test('should show error if environment name is empty', async () => { | ||
setupServerRoutes(); | ||
render(<OrderEnvironments />); | ||
|
||
await waitFor(async () => { | ||
const openDialogButton = await screen.queryByRole('button', { | ||
name: /view pricing/i, | ||
}); | ||
expect(openDialogButton).toBeInTheDocument(); | ||
fireEvent.click(openDialogButton!); | ||
}); | ||
|
||
const checkbox = screen.getByRole('checkbox', { | ||
name: /i understand adding environments/i, | ||
}); | ||
fireEvent.click(checkbox); | ||
|
||
const submitButton = screen.getByRole('button', { name: /order/i }); | ||
fireEvent.click(submitButton); | ||
|
||
expect( | ||
screen.getByText(/environment name is required/i), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
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
24 changes: 24 additions & 0 deletions
24
frontend/src/hooks/api/actions/useOrderEnvironmentsApi/useOrderEnvironmentsApi.ts
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,24 @@ | ||
import useAPI from '../useApi/useApi'; | ||
import type { OrderEnvironmentsSchema } from 'openapi'; | ||
|
||
export const useOrderEnvironmentApi = () => { | ||
const { makeRequest, createRequest, errors, loading } = useAPI({ | ||
propagateErrors: true, | ||
}); | ||
|
||
const orderEnvironments = async (payload: OrderEnvironmentsSchema) => { | ||
const req = createRequest('api/admin/order-environments', { | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
const res = await makeRequest(req.caller, req.id); | ||
return res.json(); | ||
}; | ||
|
||
return { | ||
orderEnvironments, | ||
errors, | ||
loading, | ||
}; | ||
}; |
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,13 @@ | ||
/** | ||
* Generated by Orval | ||
* Do not edit manually. | ||
* See `gen:api` script in package.json | ||
*/ | ||
|
||
/** | ||
* A request for hosted customers to order new environments in Unleash. | ||
*/ | ||
export interface OrderEnvironmentsSchema { | ||
/** An array of environment names to be ordered. */ | ||
environments: string[]; | ||
} |