Skip to content

Commit

Permalink
Feature/Logic path
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryczko committed May 11, 2024
1 parent 2471a13 commit 03539d0
Show file tree
Hide file tree
Showing 43 changed files with 1,051 additions and 235 deletions.
1 change: 1 addition & 0 deletions cypress/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": ["plugin:cypress/recommended"],
"plugins": ["cypress"],
"rules": {
"cypress/unsafe-to-chain-command": "off",
"jest/expect-expect": "off",
"no-relative-import-paths/no-relative-import-paths": "off",
"@typescript-eslint/no-namespace": "off",
Expand Down
17 changes: 11 additions & 6 deletions cypress/e2e/thankyouPage.cy.ts → cypress/e2e/answerSurvey.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { faker } from '@faker-js/faker';

describe('Create and Answer Survey', () => {
it('should create a survey and answer it and show thank you page', () => {
describe('Answering survey tests', () => {
it('should create a survey, answer it and show thank you page', () => {
// Login before proceeding
cy.login();

Expand All @@ -11,10 +11,15 @@ describe('Create and Answer Survey', () => {

cy.get('[data-test-id="create-survey"]').click();
cy.url().should('include', '/survey/create');
cy.get('input[name="survey-title"]').type(surveyTitle);
cy.get('input[name="survey-title"]').clear().type(surveyTitle);

cy.get('input[data-test-id="question-input-0"]').type(questionContent);
cy.get('input[data-test-id="question-input-1"]').type(questionContent);
cy.get('input[data-test-id="question-input-0"]')
.clear()
.type(questionContent);

cy.get('input[data-test-id="question-input-1"]')
.clear()
.type(questionContent);

cy.get('button[data-test-id="options-button"]').click();
cy.get('[data-test-id="one-per-step-toggle"]').click();
Expand Down Expand Up @@ -42,7 +47,7 @@ describe('Create and Answer Survey', () => {
cy.contains('button', 'Send').should('be.visible').click();

// Verify Thank You Page
cy.url().should('include', '/thank-you');
cy.get('[data-test-id="thank-you-header"]').should('exist');
});
});
});
52 changes: 26 additions & 26 deletions cypress/e2e/login.cy.ts → cypress/e2e/authorization.cy.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { faker } from '@faker-js/faker';

describe('Login Page', () => {
it('should sign up via email and password and redirect to home page', () => {
cy.visit('/login');
cy.get('[data-test-id="signup-link"]').click();
cy.url().should('include', '/signup');
cy.title().should('include', 'Sign up');
cy.reload();
cy.title().should('include', 'Sign up');
cy.get('input[name="name"]').type(faker.name.fullName());
cy.get('input[type="email"]').type(faker.internet.email());
cy.get('input[type="password"]').type(faker.internet.password());
cy.get('form').submit();
cy.url().should('include', '/');
});

it('should not redirect to home page when login fails', () => {
cy.visit('/login');
cy.title().should('include', 'Login');
cy.get('input[type="email"]').type(faker.internet.email());
cy.get('input[type="password"]').type(faker.internet.password());
cy.get('form').submit();
cy.url().should('include', '/login');
});
});
import { faker } from '@faker-js/faker';

describe('Authorization tests', () => {
it('should not redirect to home page when login fails', () => {
cy.visit('/login');
cy.title().should('include', 'Login');
cy.get('input[type="email"]').type(faker.internet.email());
cy.get('input[type="password"]').type(faker.internet.password());
cy.get('form').submit();
cy.url().should('include', '/login');
});

it('should sign up via email and password and redirect to home page', () => {
cy.visit('/login');
cy.get('[data-test-id="signup-link"]').click();
cy.url().should('include', '/signup');
cy.title().should('include', 'Sign up');
cy.reload();
cy.title().should('include', 'Sign up');
cy.get('input[name="name"]').type(faker.name.fullName());
cy.get('input[type="email"]').type(faker.internet.email());
cy.get('input[type="password"]').type(faker.internet.password());
cy.get('form').submit();
cy.url().should('include', '/');
});
});
15 changes: 10 additions & 5 deletions cypress/e2e/createSurvey.cy.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { faker } from '@faker-js/faker';

describe('Create Survey Page', () => {
describe('Creating survey tests', () => {
it('should create a survey', () => {
const surveyTitle = faker.lorem.sentence();
const questionContent = faker.lorem.sentence();

cy.login();
cy.get('[data-test-id="create-survey"]').click();
cy.url().should('include', '/survey/create');
cy.get('input[name="survey-title"]').type(surveyTitle);

cy.get('input[data-test-id="question-input-0"]').type(questionContent);
cy.get('input[data-test-id="question-input-1"]').type(questionContent);
cy.get('input[name="survey-title"]').clear().type(surveyTitle);

cy.get('input[data-test-id="question-input-0"]')
.clear()
.type(questionContent);

cy.get('input[data-test-id="question-input-1"]')
.clear()
.type(questionContent);

cy.get('button[name="create-survey"]').click();

console.log('url', cy.url());
cy.url().should('include', '/survey/answer/');
cy.visit('/surveys');
cy.contains(surveyTitle);
Expand Down
17 changes: 9 additions & 8 deletions lib/axiosConfig.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios from 'axios';

const instance = axios.create({
baseURL: process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000',
});

export const getFetch = <T>(url: string, params = {}) => {
return instance<T>({
export const getFetch = <Res>(url: string, params = {}) => {
return instance<Res>({
method: 'GET',
url,
params,
}).then((response) => response.data);
};

export const postFetch = (url: string, data = {}) => {
return instance({
export const postFetch = <Req = any, Res = any>(url: string, data: Req) => {
return instance<Res>({
method: 'POST',
url,
data,
}).then((response) => response.data);
};

export const patchFetch = (url: string, data = {}) => {
return instance({
export const patchFetch = <Req = any, Res = any>(url: string, data: Req) => {
return instance<Res>({
method: 'PATCH',
url,
data,
}).then((response) => response.data);
};

export const putFetch = (url: string, data = {}) => {
return instance({
export const putFetch = <Req = any, Res = any>(url: string, data: Req) => {
return instance<Res>({
method: 'PUT',
url,
data,
Expand Down
7 changes: 5 additions & 2 deletions locales/en/surveyCreate.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"heading": "Create new survey",
"editHeading": "Edit survey",
"buttonCreate": "Create Survey",
"editNote": "Some action like adding and removing questions or changing answers are not available in edit mode.",
"editNote": "Some action like adding, removing questions or changing answers are not currently available in edit mode.",
"editNoteTitle": "Note",
"buttonSave": "Save changes",
"discardChanges": "Discard changes",
Expand All @@ -19,5 +19,8 @@
"fillRequiredFields": "Please fill all required fields",
"surveyCreationSucessCopiedCorrectly": "and link copied to clipboard",
"signInToCreateSurvey": "Sign in to create survey",
"options": "Display options"
"options": "Display options",
"GREATER_THAN": "Greater than",
"LESS_THAN": "Less than",
"EQUAL": "Equal"
}
47 changes: 30 additions & 17 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ model VerificationToken {
}

model Survey {
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String @db.ObjectId
createdAt DateTime @default(now())
title String
isActive Boolean
description String?
questions Question[]
answers Answer[]
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String @db.ObjectId
createdAt DateTime @default(now())
title String
isActive Boolean
description String?
questions Question[]
answers Answer[]
oneQuestionPerStep Boolean
displayTitle Boolean
hideProgressBar Boolean?
Expand All @@ -89,16 +89,17 @@ model Question {
isRequired Boolean
options String[]
order Int
logicPaths LogicPath[]
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
}


model Answer {
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String? @db.ObjectId
createdAt DateTime @default(now())
surveyId String @db.ObjectId
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String? @db.ObjectId
createdAt DateTime @default(now())
surveyId String @db.ObjectId
answerData AnswerData[]
Expand All @@ -107,17 +108,29 @@ model Answer {
}

model AnswerData {
id String @id @default(auto()) @map("_id") @db.ObjectId
answerId String @db.ObjectId
questionId String @db.ObjectId
id String @id @default(auto()) @map("_id") @db.ObjectId
answerId String @db.ObjectId
questionId String @db.ObjectId
providedAnswer String?
answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
}
answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
}

type LogicPath {
nextQuestionId String? @db.ObjectId
comparisonType ComparisonType
selectedOption String
}

enum QuestionType {
EMOJI
INPUT
CHOICE
RATE
}

enum ComparisonType {
EQUAL
GREATER_THAN
LESS_THAN
}
2 changes: 1 addition & 1 deletion src/features/authorization/components/AuthFormWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { PropsWithChildren } from 'react';
export default function AuthFormWrapper({ children }: PropsWithChildren) {
return (
<section className="mx-auto flex flex-col items-center justify-center lg:mt-6">
<div className="mt-4 w-full rounded-lg border bg-white/50 p-6 shadow-sm sm:max-w-md">
<div className="mt-4 w-full rounded-lg border bg-white p-6 shadow-sm sm:max-w-md">
{children}
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Button, {
} from 'shared/components/Button/Button';
import NewQuestionModal from 'features/surveys/features/SurveyCreator/components/NewQuestionModal/NewQuestionModal';
import useModal from 'features/surveys/hooks/useModal';
import { Question } from 'features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager';
import { DraftQuestion } from 'features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager';

interface AddQuestionButtonProps {
onClick: (newQuestion: Question) => void;
onClick: (newQuestion: DraftQuestion) => void;
}

export const AddQuestionButton = ({ onClick }: AddQuestionButtonProps) => {
Expand Down
Loading

0 comments on commit 03539d0

Please sign in to comment.