Skip to content

Commit

Permalink
Merge branch 'resitAdel' of https://github.com/Adel-Atzouza/CargoHub
Browse files Browse the repository at this point in the history
…into resitAdel
  • Loading branch information
SvenvanMuiden committed Feb 7, 2025
2 parents eacc956 + 8bd1086 commit 71f2977
Show file tree
Hide file tree
Showing 8 changed files with 2,010 additions and 1,784 deletions.
5 changes: 2 additions & 3 deletions CargoHub/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public static void Main(string[] args)
builder.Services.AddScoped<OrderStorageService>();
builder.Services.AddScoped<ShipmentStorageService>();
builder.Services.AddScoped<ClientStorageService>();
// builder.Services.AddScoped<ShipmentService>();
// builder.Services.AddScoped<ClassificationService>();

builder.Services.AddScoped<WarehouseStorageService>();

builder.Services.AddScoped<MigrationsService>();
// builder.Services.AddScoped<ReportService>();
builder.Services.AddScoped<APIKeyService>();
Expand Down
199 changes: 199 additions & 0 deletions Tests/test_ordersController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import requests
import test_helper as helper

ORDERS_URL = "http://localhost:3000/api/v2/orders"
CLIENTS_URL = "http://localhost:3000/api/v2/Clients"
WAREHOUSES_URL = "http://localhost:3000/api/v2/warehouses"
ITEMS_URL = "http://localhost:3000/api/v2/Items"
INVENTORIES_URL = "http://localhost:3000/api/v2/inventories"
LOCATIONS_URL = "http://localhost:3000/api/v2/Locations"


HEADERS = {"Content-Type": "application/json",
'APIKEY': "4125a7b2-7ef8-4c4f-9ff9-3386c0dbcb5c"}
TestOrder_1 = {
"source_id": 1,
"order_date": "2024-11-19T13:39:16.5035533Z",
"request_date": "2024-11-19T13:39:16.5035533Z",
"reference": "ORD123",
"reference_extra": "Urgent Delivery",
"order_status": "Delivered",
"notes": "Order notes",
"shipping_notes": "Handle with care",
"picking_notes": "Fragile items",
"warehouse_id": 1,
"ship_to": 1,
"bill_to": 1,
"shipment_id": None,
"total_amount": 200.00,
"total_discount": 10.00,
"total_tax": 5.00,
"total_surcharge": 2.00,
"Items":
[
{
"Item_Id": "P000001",
"Amount": 70
}

]

}

TestClient_1 = {
"id": 1,
"name": "Raymond Inc",
"address": "1296 Daniel Road Apt. 349",
"city": "Pierceview",
"zip_code": "28301",
"province": "Colorado",
"country": "United States",
"contact_name": "Bryan Clark",
"contact_phone": "242.732.3483x2573",
"contact_email": "robertcharles@example.net",
}

Test_Warehouse_1 = {
"id": 0,
"code": "GIOMNL90",
"name": "Petten longterm hub",
"address": "Owenweg 731",
"zip": "4615 RB",
"city": "Petten",
"province": "Noord-Holland",
"country": "NL",
"contact": {
"name": "Maud Adryaens",
"phone": "+31836 752702",
"email": "nickteunissen@example.com"
},
}

Test_Item_1 = {
"code": "ABC123",
"description": "Sample item",
"short_description": "Sample short description",
"upc_code": "123456789",
"model_number": "XYZ123",
"commodity_code": "A123",
"item_line": 2,
"item_group": 2,
"item_type": 2,
"unit_purchase_quantity": 10,
"unit_order_quantity": 5,
"pack_order_quantity": 5,
"supplier_id": 1,
"supplier_code": "SUP123",
"supplier_part_number": "PART123",
}
Test_Inventory_1 = {
"item_Id": "",
"description": "RandomDescription",
"item_Reference": "REF456",
"locations": [
],
"total_on_Hand": 500,
"total_Expected": 0,
"total_Ordered": 0,
"total_Allocated": 0,
"total_Available": 500,
}

Test_Location_1 = {
"Warehouse_id": 0,
"Code": "LOC001",
"Name": "Main Storage"
}


def Post_test_order():
response = requests.post(
ORDERS_URL, headers=HEADERS, json=TestOrder_1)
return response.status_code


def post_test_warehouse():
response = requests.post(
WAREHOUSES_URL, headers=HEADERS, json=Test_Warehouse_1)
json = str(response.json())
generated_id = helper.get_integer_from_json_string(json)
return generated_id


def post_test_client():
response = requests.post(
CLIENTS_URL, headers=HEADERS, json=TestClient_1)
json = str(response.json())
generated_id = helper.get_integer_from_json_string(json)
return generated_id


def post_test_item():
response = requests.post(ITEMS_URL, headers=HEADERS, json=Test_Item_1)
# the response is the generated item uid
return response.text


def post_test_location(warehouse_id):
Test_Location_1["Warehouse_id"] = warehouse_id

response = requests.post(
LOCATIONS_URL, headers=HEADERS, json=Test_Location_1)
json = str(response.json())
generated_id = helper.get_integer_from_json_string(json)
return generated_id


def post_test_inventory(item_uid, location_id):
Test_Inventory_1["locations"].append(location_id)
Test_Inventory_1["item_Id"] = item_uid

response = requests.post(
INVENTORIES_URL, headers=HEADERS, json=Test_Inventory_1)
json = str(response.json())
generated_id = helper.get_integer_from_json_string(json)
return generated_id

## This test checks if the api requires valid: items, inventories, locations, warehouses and clients in order to create an order
def test_order_requires_dependencies():
# test adding an order with clients that don't exist in the database
post_order_without_clients = Post_test_order()

assert post_order_without_clients == 400

# Add a client and then try to add Order
generated_id_for_client = post_test_client()

# assign the client to the test_order
TestOrder_1["bill_to"] = generated_id_for_client
TestOrder_1["ship_to"] = generated_id_for_client
# try to add the order again
post_order_without_warehouse = Post_test_order()

# the response should still be 400 because warehouse doesn't exist
assert post_order_without_warehouse == 400

# add a warehouse and then try to add Order
generated_id_for_warehouse = post_test_warehouse()

# assign the warehouse to the test_order
TestOrder_1["warehouse_id"] = generated_id_for_warehouse

# add an item with its inventory and location to the database and assign that item to the order
generated_id_for_location = post_test_location(generated_id_for_warehouse)
generated_id_for_item = post_test_item()

post_test_inventory(generated_id_for_item, generated_id_for_location)

TestOrder_1["Items"] = [{
"Item_Id": generated_id_for_item,
"Amount": 200
}]

## check that you can't add an order with a delivered status (status should be pending)
assert Post_test_order() == 400

## assert that the order has been added succesfully
TestOrder_1["order_status"] = "Pending"
assert Post_test_order() == 201

1 change: 1 addition & 0 deletions UnitTest/GolbalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
global using Microsoft.VisualStudio.CodeCoverage;
global using CargoHub;
global using CargoHub.Models;
global using CargoHub.Services;
global using Microsoft.EntityFrameworkCore;
Expand Down
5 changes: 4 additions & 1 deletion UnitTest/ItemStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class ItemStorageServiceTests
{
private ItemStorageService _itemStorageService;
private AppDbContext _dbContext;
private InventoryStorageService _inventoryStorageService;

[TestInitialize]
public void Setup()
Expand All @@ -14,7 +15,9 @@ public void Setup()
.Options;

_dbContext = new AppDbContext(options);
_itemStorageService = new ItemStorageService(_dbContext);
_inventoryStorageService = new InventoryStorageService(_dbContext);

_itemStorageService = new ItemStorageService(_dbContext, _inventoryStorageService);
}

[TestCleanup]
Expand Down
1 change: 1 addition & 0 deletions UnitTest/ItemTypesServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace CargoHub.Test;

[TestClass]
Expand Down
23 changes: 23 additions & 0 deletions UnitTest/OrderStorageServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[TestClass]
public class OrderStorageServiceTest
{
private AppDbContext appDbContext;

Check warning on line 4 in UnitTest/OrderStorageServiceTest.cs

View workflow job for this annotation

GitHub Actions / unit-tests

Non-nullable field 'appDbContext' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
private OrderStorageService _service;

Check warning on line 5 in UnitTest/OrderStorageServiceTest.cs

View workflow job for this annotation

GitHub Actions / unit-tests

Non-nullable field '_service' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
[TestInitialize]
public void SetUp()
{
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
.Options;

appDbContext = new AppDbContext(options);

_service = new OrderStorageService(appDbContext);
}

[TestMethod]
public void OrderStorageService_Create()
{

}
}
Loading

0 comments on commit 71f2977

Please sign in to comment.