Skip to content

Commit

Permalink
Merge branch 'PalisadoesFoundation:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JamarTG authored Nov 29, 2023
2 parents e3c6b0d + 655b6b3 commit dc16451
Show file tree
Hide file tree
Showing 23 changed files with 426 additions and 89 deletions.
37 changes: 18 additions & 19 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Route, Switch } from 'react-router-dom';
import { useQuery } from '@apollo/client';
import * as installedPlugins from 'components/plugins/index';
Expand Down Expand Up @@ -63,6 +63,23 @@ function app(): JSX.Element {

const { data, loading } = useQuery(CHECK_AUTH);

useEffect(() => {
if (data) {
localStorage.setItem(
'name',
`${data.checkAuth.firstName} ${data.checkAuth.lastName}`
);
localStorage.setItem('id', data.checkAuth._id);
localStorage.setItem('email', data.checkAuth.email);
localStorage.setItem('IsLoggedIn', 'TRUE');
localStorage.setItem('UserType', data.checkAuth.userType);
localStorage.setItem('FirstName', data.checkAuth.firstName);
localStorage.setItem('LastName', data.checkAuth.lastName);
localStorage.setItem('UserImage', data.checkAuth.image);
localStorage.setItem('Email', data.checkAuth.email);
}
}, [data, loading]);

const extraRoutes = Object.entries(installedPlugins).map(
(plugin: any, index) => {
const extraComponent = plugin[1];
Expand All @@ -79,24 +96,6 @@ function app(): JSX.Element {
if (loading) {
return <Loader />;
}

if (data) {
localStorage.setItem(
'name',
`${data.checkAuth.firstName} ${data.checkAuth.lastName}`
);
localStorage.setItem('id', data.checkAuth._id);
localStorage.setItem('email', data.checkAuth.email);
localStorage.setItem('IsLoggedIn', 'TRUE');
localStorage.setItem('UserType', data.checkAuth.userType);
localStorage.setItem('FirstName', data.checkAuth.firstName);
localStorage.setItem('LastName', data.checkAuth.lastName);
localStorage.setItem('UserImage', data.checkAuth.image);
localStorage.setItem('Email', data.checkAuth.email);
} else {
localStorage.clear();
}

return (
<>
<Switch>
Expand Down
19 changes: 19 additions & 0 deletions src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ export const LOGIN_MUTATION = gql`
}
`;

// to get the refresh token

export const REFRESH_TOKEN_MUTATION = gql`
mutation RefreshToken($refreshToken: String!) {
refreshToken(refreshToken: $refreshToken) {
refreshToken
accessToken
}
}
`;

// to revoke a refresh token

export const REVOKE_REFRESH_TOKEN = gql`
mutation RevokeRefreshTokenForUser {
revokeRefreshTokenForUser
}
`;

// To verify the google recaptcha

export const RECAPTCHA_MUTATION = gql`
Expand Down
10 changes: 5 additions & 5 deletions src/components/Advertisements/Advertisements.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useEffect, useState } from 'react';
import PropTypes from 'react';
import styles from './Advertisement.module.css';
import styles from './Advertisements.module.css';
import { useQuery } from '@apollo/client';
import { ADVERTISEMENTS_GET, PLUGIN_GET } from 'GraphQl/Queries/Queries'; // PLUGIN_LIST
import { useSelector } from 'react-redux';
Expand Down Expand Up @@ -138,8 +138,8 @@ export default function advertisements(): JSX.Element {
name={ad.name}
type={ad.type}
orgId={ad.orgId}
startDate={ad.startDate}
endDate={ad.endDate}
startDate={new Date(ad.startDate)}
endDate={new Date(ad.endDate)}
// getInstalledPlugins={getInstalledPlugins}
/>
)
Expand Down Expand Up @@ -175,8 +175,8 @@ export default function advertisements(): JSX.Element {
name={ad.name}
type={ad.type}
orgId={ad.orgId}
startDate={ad.startDate}
endDate={ad.endDate}
startDate={new Date(ad.startDate)}
endDate={new Date(ad.endDate)}
// getInstalledPlugins={getInstalledPlugins}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function advertisementEntry({
return (
<>
<Row data-testid="AdEntry" xs={1} md={2} className="g-4">
{Array.from({ length: 4 }).map((_, idx) => (
{Array.from({ length: 1 }).map((_, idx) => (
<Col key={idx}>
<Card>
<Card.Img
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react';

import {
ApolloClient,
ApolloProvider,
InMemoryCache,
ApolloLink,
HttpLink,
} from '@apollo/client';

import type { NormalizedCacheObject } from '@apollo/client';
import { BrowserRouter } from 'react-router-dom';
import AdvertisementRegister from './AdvertisementRegister';
import { Provider } from 'react-redux';
import { store } from 'state/store';
import { BACKEND_URL } from 'Constant/constant';
import i18nForTest from 'utils/i18nForTest';
import { I18nextProvider } from 'react-i18next';
import i18n from 'utils/i18nForTest';

const httpLink = new HttpLink({
uri: BACKEND_URL,
headers: {
authorization: 'Bearer ' + localStorage.getItem('token') || '',
},
});

const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
cache: new InMemoryCache(),
link: ApolloLink.from([httpLink]),
});

const translations = JSON.parse(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
JSON.stringify(i18n.getDataByLanguage('en')?.translation.advertisement!)
);

describe('Testing Advertisement Register Component', () => {
test('AdvertismentRegister component loads correctly', async () => {
const { getByText } = render(
<ApolloProvider client={client}>
<Provider store={store}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
{
<AdvertisementRegister
endDate={new Date()}
startDate={new Date()}
type="BANNER"
name="Advert1"
orgId="1"
link="google.com"
/>
}
</I18nextProvider>
</BrowserRouter>
</Provider>
</ApolloProvider>
);
await waitFor(() => {
expect(getByText(translations.addNew)).toBeInTheDocument();
});
});
test('opens and closes modals on button click', async () => {
const { getByText, queryByText } = render(
<ApolloProvider client={client}>
<Provider store={store}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
{
<AdvertisementRegister
endDate={new Date()}
startDate={new Date()}
type="BANNER"
name="Advert1"
orgId="1"
link="google.com"
/>
}
</I18nextProvider>
</BrowserRouter>
</Provider>
</ApolloProvider>
);
await waitFor(() => {
fireEvent.click(getByText(translations.addNew));
expect(queryByText(translations.RClose)).toBeInTheDocument();

fireEvent.click(getByText(translations.RClose));
expect(queryByText(translations.close)).not.toBeInTheDocument();
});
});
test('submits the form and shows success toast on successful advertisement creation', async () => {
const { getByText, getByLabelText } = render(
<ApolloProvider client={client}>
<Provider store={store}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
{
<AdvertisementRegister
endDate={new Date()}
startDate={new Date()}
type="BANNER"
name="Advert1"
orgId="1"
link="google.com"
/>
}
</I18nextProvider>
</BrowserRouter>
</Provider>
</ApolloProvider>
);
await waitFor(() => {
fireEvent.click(getByText(translations.addNew));

fireEvent.change(getByLabelText(translations.Rname), {
target: { value: 'Test Advertisement' },
});
fireEvent.change(getByLabelText(translations.Rlink), {
target: { value: 'http://example.com' },
});
fireEvent.change(getByLabelText(translations.Rtype), {
target: { value: 'BANNER' },
});
fireEvent.change(getByLabelText(translations.RstartDate), {
target: { value: '2023-01-01' },
});
fireEvent.change(getByLabelText(translations.RendDate), {
target: { value: '2023-02-01' },
});

fireEvent.click(getByText(translations.register));
});
});
});
Loading

0 comments on commit dc16451

Please sign in to comment.