Skip to content

Commit b5ee6f7

Browse files
authored
Merge pull request #15 from DanielAraldi/fix/answer-id
Add id to identify each answers a survey answer
2 parents c9b6bd2 + 543cb38 commit b5ee6f7

File tree

23 files changed

+87
-54
lines changed

23 files changed

+87
-54
lines changed

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
lint-staged
4+
node_modules/.bin/lint-staged

src/data/protocols/db/survey/add-survey-repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AddSurveyModel } from "@/domain/usecases/survey/add-survey";
1+
import { AddSurveyModel } from "@/domain/models/survey";
22

33
export interface AddSurveyRepository {
44
add(surveyData: AddSurveyModel): Promise<void>;

src/data/usecases/survey-result/save-survey-result/db-save-survey-result.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import MockDate from "mockdate";
99
const makeFakeSurveyResultData = (): SaveSurveyResultModel => ({
1010
accountId: "any_account_id",
1111
surveyId: "any_survey_id",
12-
answer: "any_answer",
12+
answerId: "any_answer_id",
1313
date: new Date(),
1414
});
1515

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from "@/domain/models/survey";
12
export * from "@/domain/usecases/survey/add-survey";
23
export * from "@/data/protocols/db/survey/add-survey-repository";

src/data/usecases/survey/load-survey-by-id/db-load-survey-by-id.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import {
55
} from "./db-load-survey-by-id-protocols";
66
import MockDate from "mockdate";
77

8-
const makeFakeSurvey = (): SurveyModel => ({
8+
const makeFakeLoadedSurvey = (): SurveyModel => ({
99
id: "any_id",
1010
question: "any_question",
1111
answers: [
1212
{
13+
answerId: "any_answer_id",
1314
image: "any_image",
1415
answer: "any_answer",
1516
},
@@ -20,7 +21,7 @@ const makeFakeSurvey = (): SurveyModel => ({
2021
const makeLoadSurveyByIdRepository = (): LoadSurveyByIdRepository => {
2122
class LoadSurveyByIdRepositoryStub implements LoadSurveyByIdRepository {
2223
async loadById(id: string): Promise<SurveyModel | null> {
23-
return new Promise((resolve) => resolve(makeFakeSurvey()));
24+
return new Promise((resolve) => resolve(makeFakeLoadedSurvey()));
2425
}
2526
}
2627
return new LoadSurveyByIdRepositoryStub();
@@ -55,7 +56,7 @@ describe("DbLoadSurveyById Usecase", () => {
5556
test("Should return Survey on success", async () => {
5657
const { sut } = makeSut();
5758
const survey = await sut.loadById("any_id");
58-
expect(survey).toEqual(makeFakeSurvey());
59+
expect(survey).toEqual(makeFakeLoadedSurvey());
5960
});
6061

6162
test("Should throw if LoadSurveyByIdRepository throws", async () => {

src/data/usecases/survey/load-surveys/db-load-surveys.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import {
55
import { DbLoadSurveys } from "./db-load-surveys";
66
import MockDate from "mockdate";
77

8-
const makeFakeSurveys = (): SurveyModel[] => [
8+
const makeFakeLoadedSurveys = (): SurveyModel[] => [
99
{
1010
id: "any_id",
1111
question: "any_question",
1212
answers: [
1313
{
14+
answerId: "any_answer_id",
1415
image: "any_image",
1516
answer: "any_answer",
1617
},
@@ -22,6 +23,7 @@ const makeFakeSurveys = (): SurveyModel[] => [
2223
question: "other_question",
2324
answers: [
2425
{
26+
answerId: "other_answer_id",
2527
image: "other_image",
2628
answer: "other_answer",
2729
},
@@ -33,7 +35,7 @@ const makeFakeSurveys = (): SurveyModel[] => [
3335
const makeLoadSurveysRepository = (): LoadSurveysRepository => {
3436
class LoadSurveysRepositoryStub implements LoadSurveysRepository {
3537
async loadAll(): Promise<SurveyModel[]> {
36-
return new Promise((resolve) => resolve(makeFakeSurveys()));
38+
return new Promise((resolve) => resolve(makeFakeLoadedSurveys()));
3739
}
3840
}
3941
return new LoadSurveysRepositoryStub();
@@ -68,7 +70,7 @@ describe("DbLoadSurveys Usecase", () => {
6870
test("Should return a list of survey on success", async () => {
6971
const { sut } = makeSut();
7072
const surveys = await sut.load();
71-
expect(surveys).toEqual(makeFakeSurveys());
73+
expect(surveys).toEqual(makeFakeLoadedSurveys());
7274
});
7375

7476
test("Should throw if LoadSurveysRepository throws", async () => {

src/domain/models/survey-result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export type SurveyResultModel = {
22
id: string;
33
surveyId: string;
44
accountId: string;
5-
answer: string;
5+
answerId: string;
66
date: Date;
77
};

src/domain/models/survey.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export type SurveyModel = {
66
};
77

88
export type SurveyAnswerModel = {
9-
image?: string;
9+
answerId: string;
1010
answer: string;
11+
image?: string;
12+
};
13+
14+
export type AddSurveyModel = Omit<SurveyModel, "id" | "answers"> & {
15+
answers: Array<Omit<SurveyAnswerModel, "answerId">>;
1116
};

src/domain/usecases/survey/add-survey.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { SurveyAnswerModel, SurveyModel } from "@/domain/models/survey";
2-
3-
export type AddSurveyModel = Omit<SurveyModel, "id">;
1+
import { AddSurveyModel } from "@/domain/models/survey";
42

53
export interface AddSurvey {
64
add(data: AddSurveyModel): Promise<void>;

src/infra/db/mongodb/account/account-mongo-repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class AccountMongoRepository
3232

3333
async updateAccessToken(id: string, token: string): Promise<void> {
3434
const accountCollection = await MongoHelper.getCollection("accounts");
35-
const accountId = MongoHelper.toObjectId(id);
35+
const accountId = MongoHelper.objectId(id);
3636
await accountCollection.updateOne(
3737
{ _id: accountId },
3838
{ $set: { accessToken: token } }

0 commit comments

Comments
 (0)