Skip to content

Commit

Permalink
finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomass1412 committed Dec 20, 2023
1 parent d0f37f6 commit fc69557
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,6 @@ void setUp() {
invalidRequest = new CreateIntegrationRequest("InvalidName", "external", schemaList);
}

@Test
void testCreateInternalIntegration_Success() {

String collectionName = "someCollectionName";

Mono<String> collectionCreationMono = Mono.just(collectionName);
Mockito.when(integrationDataService.createCollection(validRequest)).thenReturn(collectionCreationMono);

Mockito.when(internalIntegrationRepository.save(Mockito.any(InternalIntegration.class)))
.thenAnswer(invocation -> Mono.just(invocation.getArgument(0, InternalIntegration.class)));

Mono<IntegrationResponse> result = integrationService.createInternalIntegration(validRequest);

StepVerifier.create(result)
.expectNextMatches(response -> response.getName().equals(validRequest.getName()) && response.getType().equals("internal"))
.verifyComplete();

Mockito.verify(integrationDataService).createCollection(validRequest);

Mockito.verify(internalIntegrationRepository).save(Mockito.any(InternalIntegration.class));
}

@Test
void testCreateInternalIntegration_FailureUnsupportedType() {
// Execute
Mono<IntegrationResponse> result = integrationService.createInternalIntegration(invalidRequest);

// Verify and Assert
StepVerifier.create(result)
.expectErrorMatches(throwable -> throwable instanceof IllegalArgumentException &&
throwable.getMessage().contains("Integration type 'external' is not supported"))
.verify();

Mockito.verify(integrationDataService, Mockito.never()).createCollection(Mockito.any());
}

@Test
void testCreateIntegration_Success() {

Expand Down Expand Up @@ -143,5 +107,42 @@ void testCreateIntegration_NameAlreadyExists(){
Mockito.verify(integrationRepository).findByName(validRequest.getName());
Mockito.verify(integrationRepository, Mockito.never()).save(Mockito.any());
}

@Test
void testCreateInternalIntegration_Success() {

String collectionName = "someCollectionName";

Mono<String> collectionCreationMono = Mono.just(collectionName);
Mockito.when(integrationDataService.createCollection(validRequest)).thenReturn(collectionCreationMono);

Mockito.when(internalIntegrationRepository.save(Mockito.any(InternalIntegration.class)))
.thenAnswer(invocation -> Mono.just(invocation.getArgument(0, InternalIntegration.class)));

Mono<IntegrationResponse> result = integrationService.createInternalIntegration(validRequest);

StepVerifier.create(result)
.expectNextMatches(response -> response.getName().equals(validRequest.getName()) && response.getType().equals("internal"))
.verifyComplete();

Mockito.verify(integrationDataService).createCollection(validRequest);

Mockito.verify(internalIntegrationRepository).save(Mockito.any(InternalIntegration.class));
}

@Test
void testCreateInternalIntegration_FailureUnsupportedType() {
// Execute
Mono<IntegrationResponse> result = integrationService.createInternalIntegration(invalidRequest);

// Verify and Assert
StepVerifier.create(result)
.expectErrorMatches(throwable -> throwable instanceof IllegalArgumentException &&
throwable.getMessage().contains("Integration type 'external' is not supported"))
.verify();

Mockito.verify(integrationDataService, Mockito.never()).createCollection(Mockito.any());
}

}

1 change: 1 addition & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function App() {
<Route path="/metrics" element={<Getmetric />}/>
<Route path="/newuser" element={<CreateNewUser />}/>
<Route path="/integrations/:integrationId" element={<IntegrationDetail />}/>
<Route path="/createdashboard" element={<CreateDashboard />}/>
</Route>
</Routes>
</SnackbarProvider>
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/Components/IntegrationForm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React, { useState } from 'react';
import { useSnackbar } from './SnackbarProvider';

export default function IntegrationForm() {
const [integrationName, setIntegrationName] = useState('');
const [formFields, setFormFields] = useState([{ name: '', type: 'text' }]);
const { showSnackbar } = useSnackbar();


const handleIntegrationNameChange = (event) => {
setIntegrationName(event.target.value);
Expand Down Expand Up @@ -37,10 +40,12 @@ export default function IntegrationForm() {

const data = await response.json();
console.log(data);
// Handle response or redirect user
showSnackbar('success', "Integration created successfully");
} catch (error) {
console.error(error);
// Handle error
const errorMessage = error.message || 'An error occurred while submitting the form.';
showSnackbar('error', errorMessage);

}
};

Expand Down
6 changes: 1 addition & 5 deletions frontend/src/Components/dashboardForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ export default function DashboardForm() {
setData(data.content);
console.log('Success:', data);
showSnackbar('success', 'Dashboard created successfully.');
// Handle response or redirect user

} catch (error) {
console.error(error);
const errorMessage = error.message || 'An error occurred while submitting the form.';
showSnackbar('error', errorMessage);
// Handle error
}
};

Expand Down Expand Up @@ -157,7 +156,6 @@ export default function DashboardForm() {
</select>
</div>
<div className="mt-4">
{/* Dropdown for Metric Name */}
<label htmlFor={`widget-metric-${index}`} className="block text-sm font-medium text-gray-700">
Metric Name
</label>
Expand All @@ -174,7 +172,6 @@ export default function DashboardForm() {
))}
</select>
</div>
{/* Sorted By Dropdown */}
<div className="mt-4">
<label htmlFor={`widget-sortedBy-${index}`} className="block text-sm font-medium text-gray-700">
Sort By count
Expand Down Expand Up @@ -239,7 +236,6 @@ export default function DashboardForm() {
placeholder="Enter limit"
/>
</div>
{/* Additional fields for widget options can be added here */}
<div className="mt-4">
<button
type="button"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Pages/CreateDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function Page() {
<main className="bg-green-50 h-screen flex flex-col">
<Header />
<div className="flex flex-1 items-center justify-center p-4">
<div className="w-full max-w-md"> {/* Adjust max-w-md to control the form's width */}
<div className="w-full max-w-md">
<DashboardForm />
</div>
</div>
Expand Down

0 comments on commit fc69557

Please sign in to comment.