Skip to content

Commit

Permalink
fix: Fix issues that occured when users deleted their accounts and ad…
Browse files Browse the repository at this point in the history
…d delete-account.spec.ts tests in the backend
  • Loading branch information
alepefe committed Dec 2, 2024
1 parent 764214c commit e3e6790
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
42 changes: 42 additions & 0 deletions api/test/integration/auth/delete-account.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { TestManager } from '../../utils/test-manager';
import { HttpStatus } from '@nestjs/common';
import { usersContract } from '@shared/contracts/users.contract';
import { ROLES } from '@shared/entities/users/roles.enum';

describe('Delete Account', () => {
let testManager: TestManager;

beforeAll(async () => {
testManager = await TestManager.createTestManager();
});

afterEach(async () => {
await testManager.clearDatabase();
});

afterAll(async () => {
await testManager.close();
});

test("An existing user should be able to delete it's account", async () => {
// Given a user exists with valid credentials
const user = await testManager.mocks().createUser({
role: ROLES.PARTNER,
email: '[email protected]',
isActive: true,
password: '12345678',
});

const { jwtToken } = await testManager.logUserIn(user);

// And the user tries to sign in with valid credentials
const response = await testManager
.request()
.delete(usersContract.deleteMe.path)
.set('Authorization', `Bearer ${jwtToken}`)
.send();

// We should get back OK response and an access token
expect(response.status).toBe(HttpStatus.OK);
});
});
6 changes: 2 additions & 4 deletions client/src/containers/profile/delete-account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ const DeleteAccount: FC = () => {
});

if (status === 200) {
signOut({ callbackUrl: "/auth/signin" });
}

if (status === 400 || status === 401) {
signOut({ callbackUrl: "/auth/signin", redirect: true });
} else if (status === 400 || status === 401) {
toast({
variant: "destructive",
description: body.errors?.[0].title,
Expand Down
1 change: 0 additions & 1 deletion client/src/lib/query-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function makeQueryClient() {
const client = initQueryClient(router, {
validateResponse: true,
baseUrl: process.env.NEXT_PUBLIC_API_URL as string,
credentials: "include",
});

export { client, makeQueryClient };

0 comments on commit e3e6790

Please sign in to comment.