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

Remove a biblioteca cross-fetch e muda a set-cookie-parser para devDependencies #1715

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions models/authentication.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import setCookieParser from 'set-cookie-parser';

import { ForbiddenError, UnauthorizedError } from 'errors';
import authorization from 'models/authorization.js';
import password from 'models/password.js';
Expand Down Expand Up @@ -65,13 +63,6 @@ async function injectAnonymousOrUser(request, response, next, options = {}) {
}
}

//TODO: this should be here or inside the session model?
function parseSetCookies(response) {
const setCookieHeaderValues = response.headers.raw()['set-cookie'];
const parsedCookies = setCookieParser.parse(setCookieHeaderValues, { map: true });
return parsedCookies;
}

async function createSessionAndSetCookies(userId, response) {
const sessionObject = await session.create(userId);
session.setSessionIdCookieInResponse(sessionObject.token, response);
Expand All @@ -82,6 +73,5 @@ export default Object.freeze({
hashPassword,
comparePasswords,
injectAnonymousOrUser,
parseSetCookies,
createSessionAndSetCookies,
});
100 changes: 5 additions & 95 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"rehype-external-links": "3.0.0",
"rehype-slug": "6.0.0",
"satori": "0.10.13",
"set-cookie-parser": "2.6.0",
"slug": "8.2.3",
"snakeize": "0.1.0",
"styled-components": "5.3.11",
Expand All @@ -56,7 +55,6 @@
"@vitejs/plugin-react": "4.2.1",
"autoprefixer": "10.4.17",
"concurrently": "8.2.2",
"cross-fetch": "4.0.0",
"cz-conventional-changelog": "3.3.0",
"dotenv": "16.4.1",
"dotenv-expand": "10.0.0",
Expand All @@ -74,6 +72,7 @@
"prettier": "3.2.5",
"react-email": "2.0.0",
"retry-cli": "0.7.0",
"set-cookie-parser": "2.6.0",
"vite-tsconfig-paths": "4.3.1",
"vitest": "1.3.1"
},
Expand Down
10 changes: 4 additions & 6 deletions tests/integration/api/v1/_use-cases/registration-flow.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import fetch from 'cross-fetch';
import { version as uuidVersion } from 'uuid';

import activation from 'models/activation.js';
import authentication from 'models/authentication';
import password from 'models/password.js';
import session from 'models/session.js';
import user from 'models/user.js';
Expand All @@ -23,7 +21,7 @@ describe('Use case: Registration Flow (all successfully)', () => {

test('Create account (successfully)', async () => {
const postUserResponse = await fetch(`${orchestrator.webserverUrl}/api/v1/users`, {
method: 'post',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -106,7 +104,7 @@ describe('Use case: Registration Flow (all successfully)', () => {

test('Login (successfully)', async () => {
const postSessionResponse = await fetch(`${orchestrator.webserverUrl}/api/v1/sessions`, {
method: 'post',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -128,7 +126,7 @@ describe('Use case: Registration Flow (all successfully)', () => {
const sessionObjectInDatabase = await session.findOneById(postSessionResponseBody.id);
expect(sessionObjectInDatabase.user_id).toEqual(postUserResponseBody.id);

parsedCookiesFromPost = authentication.parseSetCookies(postSessionResponse);
parsedCookiesFromPost = orchestrator.parseSetCookies(postSessionResponse);
expect(parsedCookiesFromPost.session_id.name).toEqual('session_id');
expect(parsedCookiesFromPost.session_id.value).toEqual(postSessionResponseBody.token);
expect(parsedCookiesFromPost.session_id.maxAge).toEqual(60 * 60 * 24 * 30);
Expand All @@ -138,7 +136,7 @@ describe('Use case: Registration Flow (all successfully)', () => {

test('Get user (successfully)', async () => {
const getUserResponse = await fetch(`${orchestrator.webserverUrl}/api/v1/user`, {
method: 'get',
method: 'GET',
headers: {
cookie: `session_id=${parsedCookiesFromPost.session_id.value}`,
},
Expand Down
Loading
Loading