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

Ims maintenance endpoints #1398

Merged
merged 12 commits into from
Jul 3, 2024
43 changes: 43 additions & 0 deletions src/authentication/ldapjwtAuthProvider.test.tsx
MatteoGuarnaccia5 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import mockAxios from 'axios';
import LDAPJWTAuthProvider from './ldapjwtAuthProvider';

describe('ldapJWT auth provider', () => {
MatteoGuarnaccia5 marked this conversation as resolved.
Show resolved Hide resolved
let ldapJjwtAuthProvider: LDAPJWTAuthProvider;

beforeEach(() => {
ldapJjwtAuthProvider = new LDAPJWTAuthProvider('http://localhost:8000');
MatteoGuarnaccia5 marked this conversation as resolved.
Show resolved Hide resolved
});

it('should call api to fetch maintenance state', async () => {
(mockAxios.get as jest.Mock).mockImplementation(() =>
Promise.resolve({
data: {
show: false,
message: 'test',
},
})
);

await ldapJjwtAuthProvider.fetchMaintenanceState();
expect(mockAxios.get).toHaveBeenCalledWith(
'http://localhost:8000/maintenance'
);
});

it('should call api to fetch scheduled maintenance state', async () => {
(mockAxios.get as jest.Mock).mockImplementation(() =>
Promise.resolve({
data: {
show: false,
message: 'test',
severity: 'error',
},
})
);

await ldapJjwtAuthProvider.fetchScheduledMaintenanceState();
expect(mockAxios.get).toHaveBeenCalledWith(
'http://localhost:8000/scheduled_maintenance'
);
});
});
26 changes: 26 additions & 0 deletions src/authentication/ldapjwtAuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Axios from 'axios';
import JWTAuthProvider from './jwtAuthProvider';
import { ScheduledMaintenanceState } from '../state/scigateway.types';
import { MaintenanceState } from '../state/scigateway.types';

export default class LDAPJWTAuthProvider extends JWTAuthProvider {
public fetchScheduledMaintenanceState(): Promise<ScheduledMaintenanceState> {
return Axios.get(`${this.authUrl}/scheduled_maintenance`)
.then((res) => {
return res.data;
})
.catch((err) => {
this.handleAuthError(err);

Check warning on line 13 in src/authentication/ldapjwtAuthProvider.tsx

View check run for this annotation

Codecov / codecov/patch

src/authentication/ldapjwtAuthProvider.tsx#L12-L13

Added lines #L12 - L13 were not covered by tests
joelvdavies marked this conversation as resolved.
Show resolved Hide resolved
});
}

public fetchMaintenanceState(): Promise<MaintenanceState> {
return Axios.get(`${this.authUrl}/maintenance`)
.then((res) => {
return res.data;
})
.catch((err) => {
this.handleAuthError(err);

Check warning on line 23 in src/authentication/ldapjwtAuthProvider.tsx

View check run for this annotation

Codecov / codecov/patch

src/authentication/ldapjwtAuthProvider.tsx#L22-L23

Added lines #L22 - L23 were not covered by tests
});
}
}
5 changes: 5 additions & 0 deletions src/state/reducers/scigateway.reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import NullAuthProvider from '../../authentication/nullAuthProvider';
import { Step } from 'react-joyride';
import ICATAuthProvider from '../../authentication/icatAuthProvider';
import LDAPJWTAuthProvider from '../../authentication/ldapjwtAuthProvider';

export const authState: AuthState = {
failedToLogin: false,
Expand Down Expand Up @@ -365,6 +366,10 @@
provider = new JWTAuthProvider(payload.authUrl);
break;

case 'ldapjwt':
MatteoGuarnaccia5 marked this conversation as resolved.
Show resolved Hide resolved
provider = new LDAPJWTAuthProvider(payload.authUrl);
break;

Check warning on line 371 in src/state/reducers/scigateway.reducer.tsx

View check run for this annotation

Codecov / codecov/patch

src/state/reducers/scigateway.reducer.tsx#L369-L371

Added lines #L369 - L371 were not covered by tests

case 'github':
provider = new GithubAuthProvider(payload.authUrl);
break;
Expand Down
Loading