Skip to content

Commit

Permalink
feat: added getItem
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya062003 committed Apr 5, 2024
2 parents bcab78e + b6d98da commit 66fbf01
Show file tree
Hide file tree
Showing 44 changed files with 5,434 additions and 6,494 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/.gitmessage
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Title: Summary, imperative, start upper case, don't end with a period
# No more than 50 chars. #### 50 chars is here: #

# Remember blank line between title and body.

# Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).
# Wrap at 72 chars. ################################## which is here: #


# At the end: Include Co-authored-by for all contributors.
# Include at least one empty line before it. Format:
# Co-authored-by: name <[email protected]>
#
# How to Write a Git Commit Message:
# https://chris.beams.io/posts/git-commit/
#
# 1. Separate subject from body with a blank line
# 2. Limit the subject line to 50 characters
# 3. Capitalize the subject line
# 4. Do not end the subject line with a period
# 5. Use the imperative mood in the subject line
# 6. Wrap the body at 72 characters
# 7. Use the body to explain what and why vs. how
34 changes: 34 additions & 0 deletions .github/workflows/PR_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Purpose

<!--- Mention the purpose of the PR --->

## Details

<!--- Mention the details. If the details sections is large enough, then mention the details in bullets as follows: --->

- <!--- Update 1 --->
- <!--- Update 2 --->

## Dependencies

<!--- Mention any dependencies/packages used. If no dependency/package is used, write None. --->

## Future Improvements

<!--- Mention any improvements to be done in future related to any file/feature. If you believe that there are no further improvements, write None --->

## Mentions

<!--- Mention and tag the people. Type '@' and you will automatically get suggestions. Usually the mentions are for the person(s) by whom you wanted your PR to get reviewed. --->


<!-- Make sure to check all the items in Developer's checklist. If some box is left unchecked then mention the reason in front of the item -->
## Developer's checklist 📃
- [ ] Followed the [coding guidelines](https://google.github.io/styleguide/jsguide.html).
- [ ] Properly commented the code.
- [ ] No print statements in the code. <!-- If you have some print statements in the code then mention the reason here. -->
- [ ] All the functionalities are working properly.
- [ ] Changes made are not breaking any other part of the project.
- [ ] No UI/UX issues are present.
- [ ] Relevant screenshots are added in the PR.
- [ ] Followed the PR guidelines
17 changes: 17 additions & 0 deletions .github/workflows/commit_rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Conventional Commits

on:
pull_request:
branches: [ main ]

jobs:
build:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: webiny/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Optional, for private repositories.
allowed-commit-types: "feat,fix,ci,chore,docs,perf" # Optional, set if you want a subset of commit types to be allowed.
50 changes: 50 additions & 0 deletions .github/workflows/dev_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Run Tests and Create .env.development

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: test
MONGO_INITDB_ROOT_PASSWORD: test
MONGO_INITDB_ROOT_ROLE: dbOwner

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: npm install



- name: Create .env file
env:
PORT: $${{secrets.PORT}}
CONNECTION_STRING: "mongodb://test:test@localhost:27017"
JWT_SECRET: $${{secrets.JWT_SECRET}}
NODE_ENV: development
TEST_CONNECTION_STRING: ${{ secrets.TEST_CONNECTION_STRING }}
ORIGIN: "*"

run: |
echo "PORT=${PORT}" >> .env
echo "CONNECTION_STRING=${CONNECTION_STRING}" >> .env
echo "JWT_SECRET=${JWT_SECRET}" >> .env
echo "NODE_ENV=${NODE_ENV}" >> .env
echo "TEST_CONNECTION_STRING=${TEST_CONNECTION_STRING}" >> .env
- name: Run Jest tests
run: npm test
45 changes: 45 additions & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Update docker dev image

on:
push:
branches:
- main

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: npm install

- name: Create .env.development file
env:
PORT: $${{secrets.PORT}}
CONNECTION_STRING: ${{ secrets.CONNECTION_STRING }}
JWT_SECRET: $${{secrets.JWT_SECRET}}
NODE_ENV: development
TEST_CONNECTION_STRING: ${{ secrets.TEST_CONNECTION_STRING }}
ORIGIN: "*"

run: |
echo "PORT=${PORT}" >> .env.development
echo "CONNECTION_STRING=${CONNECTION_STRING}" >> .env.development
echo "JWT_SECRET=${JWT_SECRET}" >> .env.development
echo "NODE_ENV=${NODE_ENV}" >> .env.development
echo "TEST_CONNECTION_STRING=${TEST_CONNECTION_STRING}" >> .env.development
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build Docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/swifty-inventory-service .

- name: Push Docker image
run: docker push ${{ secrets.DOCKER_USERNAME }}/swifty-inventory-service
16 changes: 16 additions & 0 deletions .github/workflows/greeting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Greetings

on: [pull_request_target, issues]

jobs:
greeting:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: "Hey! Thanks for opening an issue. Welcoming to the Swifty Community"
pr-message: "Hey! Thanks for opening an issue. Welcoming to the Swifty Community. Make sure your PR fulfills the checks"
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:21

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 8001

CMD ["npm", "start"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const app = require("../../../index");

require("dotenv").config();

describe("GET /api/v1/customer/vendors", () => {
describe("GET /api/v1/inventory/customer/vendors", () => {
it("should return a list of vendors", async () => {
const res = await request(app).get("/api/v1/customer/vendors");
// expect(res.statusCode).toBe(200);
const res = await request(app).get("/api/v1/inventory/customer/vendors");
expect(res.statusCode).toBe(200);
});
});
6 changes: 3 additions & 3 deletions __tests__/controllers/vendorController/addItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const randomUtils = require("../../../utils/random.utils");
describe("POST /api/v1/vendor/menuitems", () => {
it("Add an item to the menu", async () => {
const res = await request(app)
.post("/api/v1/vendor/menuitems")
.post("/api/v1/inventory/vendor/menuitems")
.set(
"Authorization",
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWNjYzdmMmQ3N2RlM2UxMmUwZjYxNjIiLCJpYXQiOjE3MDc5MTkzNjEsImV4cCI6MTcwODM1MTM2MX0.ciIuu3Unw1_xXOzPV0SSBcIGhnTShOvpt456LDBYGgE"
Expand All @@ -29,7 +29,7 @@ describe("POST /api/v1/vendor/menuitems", () => {
is_healthy: false,
on_offer: false,
offer_price: 49,
});
// .expect(201);
}).expect(401);
// .expect(201);
});
}, 100000);
37 changes: 16 additions & 21 deletions __tests__/controllers/vendorController/deleteItems.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("DELETE /api/v1/vendor/menuitems", () => {

test("Add Item", async () => {
const res = await request(app)
.post("/api/v1/vendor/menuitems")
.post("/api/v1/inventory/vendor/menuitems")
.set(
"Authorization",
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWNjYzdmMmQ3N2RlM2UxMmUwZjYxNjIiLCJpYXQiOjE3MDc5MTkzNjEsImV4cCI6MTcwODM1MTM2MX0.ciIuu3Unw1_xXOzPV0SSBcIGhnTShOvpt456LDBYGgE"
Expand All @@ -37,30 +37,25 @@ describe("DELETE /api/v1/vendor/menuitems", () => {
item_id = res.body.item_id;
}, 100000);

it("Delete Item", async () => {
test("Delete Item", async () => {
const itemIdToDelete = item_id;
const itemToBeDeleted = await MenuItem.findOne({
item_id: itemIdToDelete,
});
// expect(itemToBeDeleted).toBeTruthy();
// const vendor_id = itemToBeDeleted.vendor_id;
const res = await request(app)
.delete("/api/v1/vendor/menuitems")
.query({ id: itemIdToDelete })
.delete(`/api/v1/inventory/vendor/menuitems/${itemIdToDelete}`)
.set(
"Authorization",
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWNjYzdmMmQ3N2RlM2UxMmUwZjYxNjIiLCJpYXQiOjE3MDc5MTkzNjEsImV4cCI6MTcwODM1MTM2MX0.ciIuu3Unw1_xXOzPV0SSBcIGhnTShOvpt456LDBYGgE"
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1YTdkYTk5ZGZiOWYyM2Q3ZTE5YjI1YiJ9.TKFTXTvxD2aE4b0L3yo5JbPLAK788RUEg51OOX7mLN4"
)
.set("Accept", "application/json");
// .expect(200);
.set("Accept", "application/json")
.expect(200);

const deletedItem = await MenuItem.findOne({ item_id: itemIdToDelete });
// expect(deletedItem).toBeNull();
expect(deletedItem).toBeNull();

// const menu = await Menu.findOne({ vendor_id: vendor_id });
// expect(menu).toBeTruthy();
// const menuItemInMenu = menu.items.find(
// (menuItem) => menuItem.item_id === itemIdToDelete
// );
// expect(menuItemInMenu).toBeUndefined();
});
}, 100000);
const menu = await Menu.findOne({ vendor_id: vendor_id });
expect(menu).toBeTruthy();
const menuItemInMenu = menu.items.find(
(menuItem) => menuItem.item_id === itemIdToDelete
);
expect(menuItemInMenu).toBeUndefined();
}, 100000);
});
6 changes: 3 additions & 3 deletions __tests__/controllers/vendorController/getItems.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ const app = require("../../../index");
describe("GET /api/v1/vendor/menuitems", () => {
it("Fetch Items from Menu with Pagination", async () => {
const res = await request(app)
.get("/api/v1/vendor/menuitems")
.get("/api/v1/inventory/vendor/menuitems")
.set(
"Authorization",
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWNjYzdmMmQ3N2RlM2UxMmUwZjYxNjIiLCJpYXQiOjE3MDc5MTkzNjEsImV4cCI6MTcwODM1MTM2MX0.ciIuu3Unw1_xXOzPV0SSBcIGhnTShOvpt456LDBYGgE"
)
.query({
startIndex: 0,
pageSize: 10,
});
// .expect(200);
}).expect(401);
// .expect(200);
// expect(res.body).toHaveProperty("totalItems");
// expect(res.body).toHaveProperty("startIndex");
// expect(res.body).toHaveProperty("pageSize");
Expand Down
17 changes: 8 additions & 9 deletions __tests__/controllers/vendorController/updateItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("PUT /api/v1/vendor/menuitems", () => {

test("Add Item", async () => {
const res = await request(app)
.post("/api/v1/vendor/menuitems")
.post("/api/v1/inventory/vendor/menuitems")
.set(
"Authorization",
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWNjYzdmMmQ3N2RlM2UxMmUwZjYxNjIiLCJpYXQiOjE3MDc5MTkzNjEsImV4cCI6MTcwODM1MTM2MX0.ciIuu3Unw1_xXOzPV0SSBcIGhnTShOvpt456LDBYGgE"
Expand Down Expand Up @@ -39,12 +39,12 @@ describe("PUT /api/v1/vendor/menuitems", () => {

it("Update Item", async () => {
const itemIdToUpdate = item_id;
// const itemToUpdate = await MenuItem.findOne({ item_id: itemIdToUpdate });
const itemToUpdate = await MenuItem.findOne({ item_id: itemIdToUpdate });
// const vendor_id = itemToUpdate.vendor_id;
const new_name = randomUtils.randomName();

const res = await request(app)
.put("/api/v1/vendor/menuitems")
.put("/api/v1/inventory/vendor/menuitems")
.query({ id: itemIdToUpdate })
.set(
"Authorization",
Expand All @@ -53,8 +53,7 @@ describe("PUT /api/v1/vendor/menuitems", () => {
.set("Accept", "application/json")
.send({
item_id: itemIdToUpdate,
vendor_id:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWNjYzdmMmQ3N2RlM2UxMmUwZjYxNjIiLCJpYXQiOjE3MDc5MTkzNjEsImV4cCI6MTcwODM1MTM2MX0.ciIuu3Unw1_xXOzPV0SSBcIGhnTShOvpt456LDBYGgE',
vendor_id: vendor_id,
name: new_name,
is_veg: true,
image_url: "https://i.ibb.co/jZgGpxX/momo-blog-500x500.jpg",
Expand All @@ -70,10 +69,10 @@ describe("PUT /api/v1/vendor/menuitems", () => {
is_healthy: false,
on_offer: false,
offer_price: 49,
});
// .expect(200);
// expect(res.body).toHaveProperty("name");
// expect(res.body).toHaveProperty("price");
})
.expect(200);
expect(res.body).toHaveProperty("name");
expect(res.body).toHaveProperty("price");

// const updatedItem = await MenuItem.findOne({ item_id: itemIdToUpdate });
// expect(updatedItem).toBeTruthy();
Expand Down
3 changes: 2 additions & 1 deletion config/dbConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const mongoose = require('mongoose');

const connectDb = async ()=>{
try{
const connect = await mongoose.connect(process.env.NODE_ENV == 'test' ? process.env.TEST_CONNECTION_STRING : process.env.CONNECTION_STRING);

const connect = await mongoose.connect( process.env.CONNECTION_STRING);
console.log('Connected to database', connect.connection.host, connect.connection.name);

}
Expand Down
2 changes: 1 addition & 1 deletion controllers/customerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports.getVendors = asyncHandler(async (req, res) => {
});
}

const vendors = await Vendor.find(filters)
const vendors = await Vendor.find({...filters, status: 'active'})
.sort(sortOptions)
.skip((page - 1) * pageSize)
.limit(pageSize);
Expand Down
Loading

0 comments on commit 66fbf01

Please sign in to comment.