Skip to content

Commit

Permalink
register test
Browse files Browse the repository at this point in the history
  • Loading branch information
vvaldesc committed Jun 19, 2024
1 parent 42db30b commit c684726
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 85 deletions.
14 changes: 8 additions & 6 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export default defineConfig({
// supportFile: "cypress/support/commands.js",
supportFile: false,
},
// env: {
// googleRefreshToken: 'xxxxxxx',
// googleClientId: 'xxxxxxx',
// googleClientSecret: 'xxxxxxx',
// },
video: false,
env: {
googleRefreshToken: 'xxxxxxx',
googleClientId: 'xxxxxxx',
googleClientSecret: 'xxxxxxx',
hostApi: 'https://localhost:4321',
},
video: true,
screenshotOnRunFailure: true,
retries: {
runMode: 2,
openMode: 0,
Expand Down
43 changes: 43 additions & 0 deletions cypress/consts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const session2cookie = {
sessionState: 2,
sessionInfo: {
OAuth: { user: {
id: 1,
name: 'Víctor',
email: '[email protected]',
image: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c',
}, expires: '2024-07-18T18:33:37.885Z' },
profile: {
id: 1,
name: 'Víctor',
surname: 'Valdés Cobos',
email: '[email protected]',
phone_number: '123459789',
address: '123 Main St',
city: 'New York',
bornDate: '1990-01-01T00:00:00.000Z',
created_at: '2024-06-08T23:11:00.000Z',
updated_at: '2024-06-08T23:11:00.000Z',
username: 'johndoedd',
image: '',
active: true
},
role: 'Clients',
profilePhotoSrc: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c'
}
};

export const session1cookie = {
sessionState: 1,
sessionInfo: {
OAuth: { user: {
id: null,
name: 'Víctor',
email: '[email protected]',
image: 'https://lh3.googleusercontent.com/a/ACg8ocK8k5xB7Nf8Z3XMbfRrlDKM3U-ptY-wD509gDbfRbboUzD1PQ=s96-c',
}, expires: '2024-07-18T18:33:37.885Z' },
profile: { image: '' },
role: '',
profilePhotoSrc: 'https://lh3.googleusercontent.com/a/ACg8ocK8k5xB7Nf8Z3XMbfRrlDKM3U-ptY-wD509gDbfRbboUzD1PQ=s96-c'
}
};
46 changes: 4 additions & 42 deletions cypress/e2e/layout.cy.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
const cookieValue = {
sessionState: 2,
sessionInfo: {
OAuth: { user: {
id: 1,
name: 'Víctor',
email: '[email protected]',
image: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c',
}, expires: '2024-07-18T18:33:37.885Z' },
profile: {
id: 1,
name: 'Víctor',
surname: 'Valdés Cobos',
email: '[email protected]',
phone_number: '123459789',
address: '123 Main St',
city: 'New York',
bornDate: '1990-01-01T00:00:00.000Z',
created_at: '2024-06-08T23:11:00.000Z',
updated_at: '2024-06-08T23:11:00.000Z',
username: 'johndoedd',
image: '',
active: true
},
role: 'Clients',
profilePhotoSrc: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c'
}
};
import { session2cookie } from "../consts";


const APP_SELECTOR = '#App';
const HEADER_SELECTOR = 'header';
Expand All @@ -36,7 +10,7 @@ describe('Layout', () => {
beforeEach(() => {
// Visita la página inicial antes de cada prueba
cy.visit('/')
cy.setCookie('sessionInfoState', JSON.stringify(cookieValue));
cy.setCookie('sessionInfoState', JSON.stringify(session2cookie));
cy.visit('/')
})

Expand Down Expand Up @@ -65,16 +39,4 @@ describe('Layout', () => {
cy.get('#profileThumb_header')
.should('be.visible')
})
})

it('Profilephoto src is set', () => {
// Verifica que el atributo src del elemento img del encabezado exista
cy.visit('/')
cy.setCookie('sessionInfoState', JSON.stringify(cookieValue));
cy.visit('/')
cy.intercept('GET', 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c').as('getProfilePhoto');
cy.wait('@getProfilePhoto');
cy.get('#profileThumb_header')
.should('have.attr', 'srcset')
.and('be.a', 'image');
});
})
36 changes: 3 additions & 33 deletions cypress/e2e/perfil.cy.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,11 @@
const cookieValue = {
sessionState: 2,
sessionInfo: {
OAuth: { user: {
id: 1,
name: 'Víctor',
email: '[email protected]',
image: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c',
}, expires: '2024-07-18T18:33:37.885Z' },
profile: {
id: 1,
name: 'Víctor',
surname: 'Valdés Cobos',
email: '[email protected]',
phone_number: '123459789',
address: '123 Main St',
city: 'New York',
bornDate: '1990-01-01T00:00:00.000Z',
created_at: '2024-06-08T23:11:00.000Z',
updated_at: '2024-06-08T23:11:00.000Z',
username: 'johndoedd',
image: '',
active: true
},
role: 'Clients',
profilePhotoSrc: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c'
}
};
import { session2cookie } from "../consts";

const APP_SELECTOR = '#App';
const HEADER_SELECTOR = 'header';
const FOOTER_SELECTOR = 'footer';
const PROFILETHUMB_SELECTOR = '#profileThumb_registro';
const PROFILETHUMB_SELECTOR = '#profileThumb_registro';

describe('Perfil', () => {
beforeEach(() => {
cy.visit('/')
cy.setCookie('sessionInfoState', JSON.stringify(cookieValue));
cy.setCookie('sessionInfoState', JSON.stringify(session2cookie));
cy.visit('/perfil')
});

Expand Down
66 changes: 66 additions & 0 deletions cypress/e2e/register.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { session1cookie } from "../consts";

describe('Registro', () => {
beforeEach(() => {
cy.visit('/')
cy.setCookie('sessionInfoState', JSON.stringify(session1cookie));
cy.visit('/perfil')
});

it("Rellena y envía el formulario", () => {
// Verifica que el formulario existe
cy.get("form").should("exist").and("be.visible");

// Rellena los campos del formulario
// Rellena los campos del formulario

cy.get('input[id="name"]').should("exist").clear().type("Victor Hugo");

cy.get('input[id="surname"]')
.should("exist")
.clear()
.type("Apellido De Prueba");

cy.get('input[id="phone_number"]').should("exist").type("616587195");

cy.get('input[id="address"]')
.should("exist")
.type("Talavera de la reina");

cy.get('input[id="city"]').should("exist").type("Ciudad de prueba");

cy.get('input[id="username"]')
.should("exist")
.clear()
.type("videoclubtala0102");

cy.get('input[id="bornDate"]').should("exist").type("1990-01-01");

// Envía el formulario
cy.get('button[type="submit"]').click();
cy.get('input[id="name"]').type("Victor Hugo");
cy.get('button[type="submit"]').click();

cy.intercept('POST', 'https://localhost:4321/api/clients/clients').as('postClients');

cy.wait('@postClients').then(({ response }) => {
if (response.statusCode === 500) {
throw new Error(`Error 500 en la solicitud POST a /api/clients/clients. Respuesta: ${JSON.stringify(response.body)}`);
}

cy.log(`Respuesta del servidor POST a /api/clients/clients: ${JSON.stringify(response.body)}`);
});

cy.request('DELETE', `${Cypress.env('hostApi')}/api/clients/email/${session1cookie.sessionInfo.OAuth.user.email}`).then((response) => {
cy.log(JSON.stringify(response.body));
});


//Borrar el usuario creado
// cy.request('POST', 'https', { clave: 'valor' }).then((response) => {
// // haz algo con response.body o response.status
// })
});


});
5 changes: 3 additions & 2 deletions src/components/AntDesign/forms/Register_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Register_form: React.FC<{sessionInfoState: sessionInfoState}> = ({sessionI
function createProfile(values: Client, setError: React.Dispatch<React.SetStateAction<boolean>>, setLoadingUpload: React.Dispatch<React.SetStateAction<boolean>>) {
console.log(values);
// postFaceCheck(values.image);
postClient(values).then((response) => { if (response.status !== 201) throw new Error(response.statusText); setLoadingUpload(false); deleteCookieLoacalStorage(); window.location.reload();})
postClient(values).then((response) => { if (response.status !== 201) throw new Error(response.statusText); setLoadingUpload(false); deleteCookieLoacalStorage(); window.location.href = "/perfil";})
.catch((err) => { setError(true); });
setLoadingUpload(false);
}
Expand All @@ -43,7 +43,7 @@ const Register_form: React.FC<{sessionInfoState: sessionInfoState}> = ({sessionI
values.email = sessionInfoState.sessionInfo.OAuth.user?.email as string;
values.active = true;
if (values.name === undefined) values.username = sessionInfoState.sessionInfo.OAuth.user?.name as string;
values.image = await imageBase64(values.image) as string;
if(file) values.image = await imageBase64(values.image) as string;
const validPhoto = values.image && await postCheckProfilePhoto(file);
if(validPhoto){
createProfile(values, setError, setLoadingUpload);
Expand All @@ -54,6 +54,7 @@ const Register_form: React.FC<{sessionInfoState: sessionInfoState}> = ({sessionI
}
} catch (error) {
setError(true);
setLoadingUpload(false);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/consts/regex.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const regex = {
email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
password: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/,
phone: /^\d{10}$/,
phone: /^\d{9}$/,
url: /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/,
courseAcronym: /^[A-Z]{2}_[A-Z]{2}[0-9]$/,
regularName: /^[a-zA-Z\s]+$/,
address: /^[a-zA-Z0-9\s\.,#-]+$/,
username: /^[a-zA-Z0-9_]{4,16}$/,
username: /^[a-zA-Z0-9_]{4,24}$/,
description: /^[a-zA-Z0-9\s\.,#-]{1,200}$/,
dni: /^[0-9]{8}[A-Z]$/
};
Expand Down

0 comments on commit c684726

Please sign in to comment.