aminfelah / freedom-backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nest Logo


Logo

Back-end api

A Basic Todo CRUD API !

Reproducing the API

To run this project just run the following on the root of the project:

docker-compose up -d dev mongodb

Built With

major frameworks/libraries and technologies used to bootstrap the todo api.

(back to top)

GraphQl PlayGround

http://localhost:3000/graphql one could argue it is the uart testing because it help us see the endpoint what are they exposing


Possible GraphQl Queries and Mutations


Action Type payload arguments
Add a Todo Mutation mutation createTodo($input: CreateTodoInput!) {
createTodo(input: $input) { todoDate
todoName
todoDone
}
}
{ "input": {
"todoDate": "18-03-2022",
"todoName": "the todo name",
"todoDone": true
}
}
Get all Todos Query { allTodos {
todoDate
todoName
todoDone
}
}
None
Get a Todo Query { todoByName(todoName :"make the backend") {
todoDate
todoName
todoDone
} }
None
Modify a Todo Mutation mutation updateTodo($filter:String!,$input: UpdateTodoInput!) {
updateTodo(filter:$filter,input: $input) {
todoDate
todoName
todoDone
}
}
{"filter": "the todo to Change",
"input": {
"todoName": "the todo to Update",
"todoDone":false
}
}
Delete a Todo Mutation mutation todoDelete($filter: String!) {
todoDelete(filter: $filter) {
todoDate
todoName
todoDone
}
}
{"filter": "the todo to Delete"}

The Model Schema and The validation Pipes

@ObjectType()
export class Todo extends Document {
  @Field()
  todoDate: string;
  @IsNotEmpty()
  @MinLength(3)
  @MaxLength(99)
  @IsString()
  @Field()
  todoName: string;
  @IsBoolean()
  @Field()
  todoDone: boolean;
}
export type TodoDocument = Todo & Document;

Basic Unit Tests using Jest

to test the resolver update action example

describe('updateTodo', () => {
    it('should update the present todo', () => {
      expect(
        resolver.updateTodo('create my todo test', {
          todoName: 'create my todo test',
          todoDone: false,
        }),
      ).resolves.toContainEqual({
        todoDate: '19-03-2022',
        todoName: 'create my todo test',
        todoDone: false,
      });
    });
  });

Basic Integeration Test

testing the relation between the resolver and service because actually the resolver uses the services

Basic End 2 End Tests using

testing the server as a whole from E2E

Deployement with CI/CD on ECS

the Deployement on CI/CD using github to run the test, run the build on a new hash, and the deploymenet on aws

About


Languages

Language:TypeScript 91.3%Language:JavaScript 5.9%Language:Dockerfile 2.9%