Skip to content

Commit

Permalink
Add Cypress End to End Test
Browse files Browse the repository at this point in the history
  • Loading branch information
minsoeaung committed Mar 3, 2024
1 parent 3b6572e commit 4b57743
Show file tree
Hide file tree
Showing 30 changed files with 4,534 additions and 47 deletions.
13 changes: 12 additions & 1 deletion Backend/Controllers/ReceiptsController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Security.Claims;
using Backend.Data;
using Backend.Dtos;
using Backend.Entities;
Expand All @@ -16,6 +17,7 @@ public async Task<ActionResult<IEnumerable<Receipt>>> GetAllReceipts()
{
return await storeContext
.Receipts
.Include(r => r.AppUser)
.Include(r => r.Customer)
.Include(r => r.ReceiptItems)
.ThenInclude(ri => ri.Item)
Expand All @@ -33,6 +35,7 @@ public async Task<ActionResult<Receipt>> GetReceipt(int id)
{
var receipt = await storeContext
.Receipts
.Include(r => r.AppUser)
.Include(r => r.Customer)
.Include(r => r.ReceiptItems)
.ThenInclude(ri => ri.Item)
Expand All @@ -50,6 +53,13 @@ public async Task<ActionResult<Receipt>> GetReceipt(int id)
[HttpPost]
public async Task<IActionResult> CreateReceipt(ReceiptRequest dto)
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

int.TryParse(userId, out var validUserId);

if (validUserId == 0)
return Unauthorized();

await using var transaction = await storeContext.Database.BeginTransactionAsync();

try
Expand Down Expand Up @@ -122,7 +132,8 @@ public async Task<IActionResult> CreateReceipt(ReceiptRequest dto)
{
Customer = customer,
CreatedAt = DateTime.UtcNow,
ReceiptItems = receiptItems
ReceiptItems = receiptItems,
AppUserId = validUserId
};

await storeContext.Receipts.AddAsync(receipt);
Expand Down
Loading

0 comments on commit 4b57743

Please sign in to comment.