Skip to content

Commit e4d86ed

Browse files
committed
Update e2e tests to be compatible with new logged in user structure
1 parent 952d653 commit e4d86ed

18 files changed

+60
-63
lines changed

components/ContributorsGrid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const ContributorsGrid = ({
147147
const rowWidth = nbCols * COLLECTIVE_CARD_FULL_WIDTH + COLLECTIVE_CARD_MARGIN_X;
148148
const paddingLeft = computePaddingLeft(width, rowWidth, nbRows, maxWidthWhenNotFull);
149149
const hasScroll = rowWidth + paddingLeft > width;
150-
const loggedUserCollectiveId = get(LoggedInUser, 'CollectiveId');
150+
const loggedUserCollectiveId = get(LoggedInUser, 'legacyId');
151151
return (
152152
<FixedSizeGrid
153153
columnCount={nbCols}

components/collective-page/sections/OurTeam.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const COLLECTIVE_CARD_WIDTH = 144;
1616
* Our Team section for the About section category
1717
*/
1818
const SectionOurTeam = ({ collective, coreContributors, LoggedInUser }) => {
19-
const loggedUserCollectiveId = get(LoggedInUser, 'CollectiveId');
19+
const loggedUserCollectiveId = get(LoggedInUser, 'legacyId');
2020

2121
return (
2222
<ContainerSectionContent py={[3, 4]}>

components/dashboard/menu-items.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ import hasFeature, { FEATURES, isFeatureEnabled, isFeatureSupported } from '../.
3232
import { hasAccountMoneyManagement, isIndividualAccount, isOrganizationAccount } from '../../lib/collective';
3333
import { isOneOfTypes, isType } from '../../lib/collective-sections';
3434
import { CollectiveType } from '../../lib/constants/collectives';
35-
import { ExpenseType } from '../../lib/graphql/types/v2/graphql';
35+
import { LegalDocumentType } from '../../lib/graphql/types/v2/graphql';
3636
import { PREVIEW_FEATURE_KEYS } from '../../lib/preview-features';
37-
import { LegalDocumentType } from '@/lib/graphql/types/v2/graphql';
3837
import type { WorkspaceAccount } from '@/lib/LoggedInUser';
3938
import type LoggedInUser from '@/lib/LoggedInUser';
4039
import { isOrganization as isOrgWorkspace } from '@/lib/LoggedInUser';
40+
4141
import { ALL_SECTIONS, ROOT_SECTIONS, SECTION_LABELS } from './constants';
4242

4343
const { USER, ORGANIZATION, COLLECTIVE, FUND, EVENT, PROJECT, INDIVIDUAL } = CollectiveType;

components/dashboard/sections/AccountSettings.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { API_V1_CONTEXT } from '../../../lib/graphql/helpers';
1010
import { editCollectivePageMutation } from '../../../lib/graphql/v1/mutations';
1111
import { editCollectivePageQuery } from '../../../lib/graphql/v1/queries';
1212
import useLoggedInUser from '../../../lib/hooks/useLoggedInUser';
13+
import { loggedInUserQuery } from '@/lib/graphql/queries';
1314

1415
import SettingsForm from '../../edit-collective/Form';
1516
import Loading from '../../Loading';
1617
import { useToast } from '../../ui/useToast';
1718
import { ALL_SECTIONS } from '../constants';
18-
import { adminPanelQuery } from '../queries';
1919

2020
const AccountSettings = ({ account, section }) => {
21-
const { LoggedInUser, refetchLoggedInUser } = useLoggedInUser();
21+
const { LoggedInUser } = useLoggedInUser();
2222
const router = useRouter();
2323
const [state, setState] = React.useState({ status: undefined, result: undefined });
2424
const { toast } = useToast();
@@ -108,7 +108,7 @@ const AccountSettings = ({ account, section }) => {
108108
variables: { collective: CollectiveInputType },
109109
// It's heavy, but we need to refetch the information of the account after a mutation as fundamental
110110
// properties like its name or whether it's a fiscal host can change.
111-
refetchQueries: [{ query: adminPanelQuery, variables: { slug: account.slug } }],
111+
refetchQueries: [{ query: loggedInUserQuery }],
112112
});
113113
const updatedCollective = response.data.editCollective;
114114
setState({ ...state, status: 'saved', result: { error: null } });
@@ -120,7 +120,7 @@ const AccountSettings = ({ account, section }) => {
120120
...router.query,
121121
},
122122
});
123-
await refetchLoggedInUser();
123+
// await refetchLoggedInUser();
124124
} else {
125125
setTimeout(() => {
126126
setState({ ...state, status: null });

components/dashboard/sections/community/AccountDetail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import useLoggedInUser from '@/lib/hooks/useLoggedInUser';
1818
import formatCollectiveType from '@/lib/i18n/collective-type';
1919
import { formatCommunityRelation } from '@/lib/i18n/community-relation';
2020
import { getCountryDisplayName, getFlagEmoji } from '@/lib/i18n/countries';
21+
import { isOrganization } from '@/lib/LoggedInUser';
2122
import { getDashboardRoute } from '@/lib/url-helpers';
2223

2324
import { ContributionDrawer } from '@/components/contributions/ContributionDrawer';
@@ -60,7 +61,6 @@ import {
6061
useAssociatedCollectiveActions,
6162
} from './common';
6263
import { communityAccountDetailQuery } from './queries';
63-
import { isOrganization } from '@/lib/LoggedInUser';
6464

6565
const convertOrganizationMutation = gql`
6666
mutation ConvertOrganizationToVendor($organization: AccountReferenceInput!, $host: AccountReferenceInput!) {

components/edit-collective/actions/Archive.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { FormattedMessage } from 'react-intl';
55
import { hasAccountMoneyManagement } from '@/lib/collective';
66
import { getErrorFromGraphqlException } from '@/lib/errors';
77
import { API_V1_CONTEXT, gqlV1 } from '@/lib/graphql/helpers';
8+
import { loggedInUserQuery } from '@/lib/graphql/queries';
89

9-
import { adminPanelQuery } from '../../dashboard/queries';
1010
import MessageBox from '../../MessageBox';
1111
import StyledModal, { ModalBody, ModalFooter, ModalHeader } from '../../StyledModal';
1212
import { P } from '../../Text';
@@ -43,7 +43,8 @@ const ArchiveCollective = ({ collective }) => {
4343
const [modal, setModal] = useState({ type: defaultAction, show: false });
4444

4545
const adminPanelMutationParams = {
46-
refetchQueries: [{ query: adminPanelQuery, variables: { slug: collective.slug } }],
46+
refetchQueries: [{ query: loggedInUserQuery }],
47+
awaitRefetchQueries: true,
4748
};
4849
const [archiveCollective] = useMutation(archiveCollectiveMutation, {
4950
...adminPanelMutationParams,

components/onboarding-modal/OnboardingContentBox.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ class OnboardingContentBox extends React.Component {
3838
}
3939

4040
componentDidMount() {
41-
const member = this.props.LoggedInUser.memberOf.filter(
42-
member => member.account.legacyId === this.props.collective.id,
43-
);
4441
this.setState({
45-
admins: [{ role: 'ADMIN', member: this.props.LoggedInUser.toV1Collective(), id: member[0].id }],
42+
admins: [{ role: 'ADMIN', member: this.props.LoggedInUser.toV1Collective() }],
4643
});
4744
}
4845

pages/dashboard.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,25 @@ const DashboardPage = () => {
244244
const intl = useIntl();
245245
const router = useRouter();
246246
const { slug, section, subpath } = parseQuery(router.query);
247-
const { LoggedInUser, loadingLoggedInUser } = useLoggedInUser();
247+
const { LoggedInUser, loadingLoggedInUser, refetchLoggedInUser } = useLoggedInUser();
248248
const { workspace: savedWorkspace, setWorkspace } = useWorkspace();
249249
const isRootUser = LoggedInUser?.isRoot;
250250
const defaultSlug = savedWorkspace.slug || LoggedInUser?.slug;
251251
const activeSlug = slug || defaultSlug;
252252
const isRootDashboard = activeSlug === ROOT_PROFILE_KEY && LoggedInUser?.isRoot;
253253

254-
// adminPanelQuery still fires for badge counts, notifications, and enrichment data
255-
// const {
256-
// data,
257-
// loading: accountLoading,
258-
// error,
259-
// } = useQuery(adminPanelQuery, {
260-
// variables: { slug: activeSlug },
261-
// skip: !activeSlug || !LoggedInUser || isRootProfile,
262-
// });
263254
const account = LoggedInUser?.getWorkspace(activeSlug) ?? null;
264255

256+
// When a workspace account isn't found (e.g. navigating to a newly created event/project),
257+
// refetch once to pick up the new account in the workspace data.
258+
const lastRefetchedSlug = React.useRef<string | null>(null);
259+
React.useEffect(() => {
260+
if (activeSlug && LoggedInUser && !account && !isRootDashboard && lastRefetchedSlug.current !== activeSlug) {
261+
lastRefetchedSlug.current = activeSlug;
262+
refetchLoggedInUser();
263+
}
264+
}, [activeSlug, LoggedInUser, account, isRootDashboard, refetchLoggedInUser]);
265+
265266
const selectedSection = section || getDefaultSectionForAccount(account, LoggedInUser, isRootDashboard);
266267

267268
// Keep track of last visited workspace account and sections

test/cypress/integration/00-applications-oauth.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('OAuth Applications', () => {
88
});
99

1010
it('create and edit applications', () => {
11-
cy.login({ email: user.email, redirect: `/dashboard/${user.collective.slug}/for-developers` });
11+
cy.login({ email: user.email, redirect: `/dashboard/${user.slug}/for-developers` });
1212

1313
cy.log('Starts with an empty state');
1414
cy.contains('[data-cy="oauth-apps-list"]', "You don't have any app yet");
@@ -66,12 +66,12 @@ describe('OAuth Applications', () => {
6666

6767
it('create application with 2fa enabled', () => {
6868
cy.signup({ user: { name: 'OAuth tester', settings: { features: { adminPanel: true } } } }).then(user => {
69-
cy.login({ email: user.email, redirect: `/dashboard/${user.collective.slug}/for-developers` });
69+
cy.login({ email: user.email, redirect: `/dashboard/${user.slug}/for-developers` });
7070

7171
const secret = generateSecret({ length: 64 });
7272
cy.enableTwoFactorAuth({
7373
userEmail: user.email,
74-
userSlug: user.collective.slug,
74+
userSlug: user.slug,
7575
secret: secret,
7676
});
7777

@@ -136,7 +136,7 @@ describe('OAuth Applications', () => {
136136
// Warning: this test is dependant on the previous one. To make it independent, connect the OAuth app with
137137
it('can list & revoke authorization tokens in the admin', () => {
138138
cy.log('App is in list');
139-
cy.login({ email: user.email, redirect: `/dashboard/${user.collective.slug}/authorized-apps` });
139+
cy.login({ email: user.email, redirect: `/dashboard/${user.slug}/authorized-apps` });
140140
cy.getByDataCy('connected-oauth-app').should('have.length', 1);
141141
cy.getByDataCy('connected-oauth-app').should('contain', 'My second App');
142142

test/cypress/integration/00-personal-token.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Personal Token', () => {
1111
});
1212

1313
it('create and edit personal token', () => {
14-
cy.login({ email: user.email, redirect: `/dashboard/${user.collective.slug}/for-developers` });
14+
cy.login({ email: user.email, redirect: `/dashboard/${user.slug}/for-developers` });
1515

1616
cy.log('Starts with an empty state');
1717
cy.contains('[data-cy="personal-tokens-list"]', "You don't have any token yet");
@@ -75,12 +75,12 @@ describe('Personal Token', () => {
7575

7676
it('create application with 2fa enabled', () => {
7777
cy.signup({ user: { name: 'Personal token tester', settings: { features: { adminPanel: true } } } }).then(user => {
78-
cy.login({ email: user.email, redirect: `/dashboard/${user.collective.slug}/for-developers` });
78+
cy.login({ email: user.email, redirect: `/dashboard/${user.slug}/for-developers` });
7979

8080
const secret = generateSecret({ length: 64 });
8181
cy.enableTwoFactorAuth({
8282
userEmail: user.email,
83-
userSlug: user.collective.slug,
83+
userSlug: user.slug,
8484
secret: secret,
8585
});
8686

0 commit comments

Comments
 (0)