Skip to content

Commit

Permalink
adde some file
Browse files Browse the repository at this point in the history
added coverages

fix(review-swagger-docs): fix swagger documentation of thereview task (#114)

- add missing security tag in review docs

[Fixes #113]

adde some file

added some tests

added coverages

fix(review-swagger-docs): fix swagger documentation of thereview task (#114)

- add missing security tag in review docs

[Fixes #113]

adde some file

* fix(create-review): fix failing create review function

-add validation before processing data

[Fixes #116]

* fix(create-review): fix failing create review function

-add validation before processing data

[Fixes #116]

dockerizing project by creating containers for app & postgres (#110)

fix minor issue in deployment of render

latest commit

 Update Readme file to include Docker-specific information

 Update Readme file to include Docker-specific information

* fix(create-review): fix failing create review function

-add validation before processing data

[Fixes #116]

* fix(create-review): fix failing create review function

-add validation before processing data

[Fixes #116]

dockerizing project by creating containers for app & postgres (#110)

fix minor issue in deployment of render

latest commit

 Update Readme file to include Docker-specific information

 Update Readme file to include Docker-specific information

fix(review-swagger-docs): fix swagger documentation of thereview task (#114) (#115)

- add missing security tag in review docs

[Fixes #113]

update profile (#72) (#104)

review controller

adding testing

fix lint issue

update profile (#72) (#104)

review controller

adding testing

fix lint issue

Co-authored-by: Joslyn Manzi Karenzi <j.karenzi@alustudent.com>

fix(stripe-payment): fix minor issue in stripe payment (#120)

-  add status check on the stripe response before setting order.paid to true

[Fixes #119]
  • Loading branch information
13XAVI committed Jun 4, 2024
1 parent 726d8e1 commit 3a2e5ef
Show file tree
Hide file tree
Showing 25 changed files with 1,193 additions and 221 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/coverage
Dockerfile
.dockerignore
docker-compose.yaml
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:latest

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 3000
CMD ["npm", "run", "dev"]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ To get started with Dynamites API, follow these simple steps:
npm run test:ci
```

## Docker

Before you run that commands you must have docker installed in your PC

1. **Build the Docker Image:**
```sh
docker build -t <image_name> .
```
2. **Use Docker Compose to run Containers :**
```sh
docker-compose up
```
3. **Stop the Running Containers:**
- If running with Docker Compose:
```sh
docker-compose down
```
## Usage

Once the development server is running, you can interact with the API using HTTP requests.
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD_DEV}
POSTGRES_USER: ${DB_USER_DEV}
POSTGRES_DB: ${DB_NAME_DEV}
ports:
- '5431:5432'

app:
build: .
ports:
- '8080:3000'
depends_on:
- db
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
env_file:
- .env
42 changes: 36 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"format": "prettier --write .",
"test": "cross-env NODE_ENV=test jest --runInBand --no-cache --detectOpenHandles",
"test:ci": "cross-env NODE_ENV=test jest --runInBand --coverage --detectOpenHandles"
},
},
"repository": {
"type": "git",
"url": "git+https://github.com/atlp-rwanda/dynamites-ecomm-be.git"
Expand Down
143 changes: 143 additions & 0 deletions src/__test__/buyerWishlist.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import request from 'supertest';
import app from '../app';
import { afterAllHook, beforeAllHook } from './testSetup';
import { getBuyerToken, getVendorToken } from './testSetup';

beforeAll(beforeAllHook);
afterAll(afterAllHook);
export let buyerToken: string;
let vendorToken: string;
let productId: number;
let categoryId: number;

beforeAll(async () => {
buyerToken = await getBuyerToken();
vendorToken = await getVendorToken();

const categoryData = {
name: 'Category4',
description: 'category description',
};

const categoryResponse = await request(app)
.post('/api/v1/category')
.set('Authorization', `Bearer ${vendorToken}`)
.send(categoryData);

categoryId = categoryResponse.body.data.id;

const productData = {
name: 'New Product Two',
image: 'new_product.jpg',
gallery: [],
shortDesc: 'This is a new product',
longDesc: 'Detailed description of the new product',
categoryId: categoryId,
quantity: 10,
regularPrice: 5,
salesPrice: 4,
tags: ['tag1', 'tag2'],
type: 'Simple',
isAvailable: true,
};

const response = await request(app)
.post('/api/v1/product')
.set('Authorization', `Bearer ${vendorToken}`)
.send(productData);

productId = response.body.data.id;

const getResponse = await request(app)
.get(`/api/v1/buyer/get_product/${productId}`)
.set('Authorization', `Bearer ${buyerToken}`);

expect(getResponse.statusCode).toEqual(200);
expect(getResponse.body.msg).toEqual('Product retrieved successfully');
});

describe('POST /api/v1/buyer/addItemToWishList', () => {
it('should add an item to the wishlist', async () => {
const res = await request(app)
.post('/api/v1/buyer/addItemToWishList')
.set('Authorization', `Bearer ${buyerToken}`)
.send({
productId: productId,
time: '2024-05-21T12:00:00Z',
});

expect(res.statusCode).toEqual(201);
expect(res.body.message).toContain('Wishlist successfully created');
});

it('should not allow adding an item already in the wishlist', async () => {
await request(app)
.post('/api/v1/buyer/addItemToWishList')
.set('Authorization', `Bearer ${buyerToken}`)
.send({
productId: productId,
time: '2024-05-21T12:00:00Z',
});

const res = await request(app)
.post('/api/v1/buyer/addItemToWishList')
.set('Authorization', `Bearer ${buyerToken}`)
.send({
productId: productId,
time: '2024-05-21T12:00:00Z',
});

expect(res.statusCode).toEqual(409);
expect(res.body.message).toContain('Product is already in the wishlist');
});
});

describe('DELETE /api/v1/buyer/removeToWishList', () => {
it('should remove a product from the wishlist', async () => {
const res = await request(app)
.delete('/api/v1/buyer/removeToWishList')
.set('Authorization', `Bearer ${buyerToken}`)
.send({
productId: productId,
});

expect(res.statusCode).toEqual(200);
expect(res.body.message).toContain(
'Product successfully removed from wishlist'
);
});
});

describe('GET /api/v1/buyer/getWishList', () => {
it('should get all wishlists', async () => {
const res = await request(app)
.get('/api/v1/buyer/getWishList')
.set('Authorization', `Bearer ${buyerToken}`);

expect(res.statusCode).toEqual(200);
expect(res.body.message).toContain('Data retrieved successfully');
});
});
describe('GET /api/v1/buyer/getOneWishList', () => {
it('should get all wishlists', async () => {
const res = await request(app)
.get('/api/v1/buyer/getOneWishList')
.set('Authorization', `Bearer ${buyerToken}`);

expect(res.statusCode).toEqual(200);
expect(res.body.message).toContain('Data retrieved successfully');
});
});

describe('RemoveProductFromWishList', () => {
it('should return an error when the wishlist or product is not found', async () => {
const res = await request(app)
.delete('/api/v1/buyer/removeToWishList')
.set('Authorization', `Bearer ${buyerToken}`)
.send({
productId: 9999,
});
expect(res.statusCode).toEqual(404);
expect(res.body.message).toContain('Product not found in wishlist');
});
});
Loading

0 comments on commit 3a2e5ef

Please sign in to comment.