Skip to content

Commit

Permalink
ci: 🎡 pass env var to ci unit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskaransarkaria committed Dec 31, 2023
1 parent ad1d798 commit cca7ff3
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 16.16
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 16.6
node-version: 16.16
- name: Install dependencies
run: npm ci
- name: Linting
run: npm run lint
- name: Unit tests
run: npm run test:unit:ci
env:
PUBLIC_BUCKET_URL: https://storage.googleapis.com/enki-website
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.14.2
v16.16
2 changes: 1 addition & 1 deletion src/lib/components/Basket/Basket.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
in:fade
>
<img
src={`${PUBLIC_BUCKET_URL}/${obj.id}-0`}
src={`${PUBLIC_BUCKET_URL}/${obj.imgHash}`}
alt={`${obj.name}`}
on:click={() => goto(`/shop/product/${obj.id}`)}
class={isMobile ? "mobile-product-img" : "product-img"}
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/basketProduct.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface BasketProduct {
name: string;
id: number;
imgHash: string;
categoryId: number;
quantity: number;
price: number;
Expand Down
12 changes: 11 additions & 1 deletion src/lib/utils/basket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const mockProduct = {
CurrentStock: 1,
CategoryId: 999,
Description: "big animal",
ProductImages: [],
ProductImages: [
{
ImageUrl: "/foobar-0-9sjs9s.jpg",
},
],
ProductTags: [],
VariantGroupId: null,
ProductDetails: {
Expand All @@ -25,6 +29,7 @@ describe("GIVEN updateBasket()", () => {
categoryId: mockProduct.CategoryId,
name: mockProduct.Name,
quantity: 1,
imgHash: "foobar-0-9sjs9s",
price: mockProduct.SalePrice,
currentStock: mockProduct.CurrentStock,
giftWrap: false,
Expand All @@ -44,6 +49,7 @@ describe("GIVEN updateBasket()", () => {
categoryId: mockProduct.CategoryId,
name: mockProduct.Name,
quantity: 1,
imgHash: "foobar-0-9sjs9s",
price: mockProduct.SalePrice,
currentStock: mockProduct.CurrentStock,
giftWrap: false,
Expand All @@ -59,6 +65,7 @@ describe("GIVEN updateBasket()", () => {
categoryId: mockProduct.CategoryId,
name: mockProduct.Name,
quantity: 2,
imgHash: "foobar-0-9sjs9s",
price: mockProduct.SalePrice,
currentStock: mockProduct.CurrentStock,
giftWrap: false,
Expand All @@ -78,6 +85,7 @@ describe("GIVEN updateBasket()", () => {
categoryId: mockProduct.CategoryId,
name: mockProduct.Name,
quantity: 2,
imgHash: "foobar-0-9sjs9s",
price: mockProduct.SalePrice,
currentStock: mockProduct.CurrentStock,
giftWrap: false,
Expand All @@ -93,6 +101,7 @@ describe("GIVEN updateBasket()", () => {
categoryId: mockProduct.CategoryId,
name: mockProduct.Name,
quantity: 1,
imgHash: "foobar-0-9sjs9s",
price: mockProduct.SalePrice,
currentStock: mockProduct.CurrentStock,
giftWrap: false,
Expand All @@ -112,6 +121,7 @@ describe("GIVEN updateBasket()", () => {
categoryId: mockProduct.CategoryId,
name: mockProduct.Name,
quantity: 1,
imgHash: "foobar-0-9sjs9s",
price: mockProduct.SalePrice,
currentStock: mockProduct.CurrentStock,
giftWrap: false,
Expand Down
21 changes: 19 additions & 2 deletions src/lib/utils/basket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BasketProduct } from "$lib/types/basketProduct";
import type { Product } from "$lib/types/product";
import { getImageFilename } from "$lib/utils/getImageFilename";

const removeItemFromBasket = (
currentQuantity: number,
Expand All @@ -15,6 +16,7 @@ const removeItemFromBasket = (
categoryId: list[listIndx].categoryId,
name: list[listIndx].name,
quantity: list[listIndx].quantity - 1,
imgHash: list[listIndx].imgHash,
price: list[listIndx].price,
currentStock: list[listIndx].currentStock,
giftWrap: list[listIndx].giftWrap ?? false,
Expand All @@ -34,6 +36,7 @@ const addItemToBasket = (
categoryId: list[listIndx].categoryId,
name: list[listIndx].name,
quantity: list[listIndx].quantity + 1,
imgHash: list[listIndx].imgHash,
price: list[listIndx].price,
currentStock: list[listIndx].currentStock,
giftWrap: list[listIndx].giftWrap ?? false,
Expand All @@ -46,7 +49,12 @@ const addItemToBasket = (
const addNewItemToBasket = (
product: Pick<
Product,
"Id" | "Name" | "SalePrice" | "CurrentStock" | "CategoryId"
| "Id"
| "Name"
| "SalePrice"
| "CurrentStock"
| "CategoryId"
| "ProductImages"
>,
list: BasketProduct[]
): BasketProduct[] => [
Expand All @@ -55,6 +63,10 @@ const addNewItemToBasket = (
categoryId: product.CategoryId,
name: product.Name,
quantity: 1,
imgHash:
product?.ProductImages?.length > 0
? getImageFilename(product.ProductImages[0].ImageUrl)
: "/coming-soon.png",
price: product.SalePrice,
currentStock: product.CurrentStock,
giftWrap: false,
Expand All @@ -67,7 +79,12 @@ const addNewItemToBasket = (
export const updateBasket = (
product: Pick<
Product,
"Id" | "Name" | "SalePrice" | "CurrentStock" | "CategoryId"
| "Id"
| "Name"
| "SalePrice"
| "CurrentStock"
| "CategoryId"
| "ProductImages"
>,
list: BasketProduct[],
updateType: string
Expand Down
25 changes: 17 additions & 8 deletions tests/mocks/categories/GET.mock
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,64 @@ Access-Control-Allow-Origin: *
"Name": "Books",
"ParentId": null,
"Children": [],
"NominalCode": ""
"NominalCode": "",
"Description": "1876023"

},
{
"Id": 2,
"Name": "Lion",
"ParentId": null,
"Children": [],
"NominalCode": ""
"NominalCode": "",
"Description": "2"
},
{
"Id": 3,
"Name": "Zebra",
"ParentId": null,
"Children": [],
"NominalCode": ""
"NominalCode": "",
"Description": "3"
},
{
"Id": 4,
"Name": "Hippopotamus",
"ParentId": null,
"Children": [],
"NominalCode": ""
"NominalCode": "",
"Description": "4"
},
{
"Id": 5,
"Name": "Water Buffalo",
"ParentId": null,
"Children": [],
"NominalCode": ""
"NominalCode": "",
"Description": "5"
},
{
"Id": 6,
"Name": "Giraffe",
"ParentId": null,
"Children": [],
"NominalCode": ""
"NominalCode": "",
"Description": "6"
},
{
"Id": 7,
"Name": "Cheetah",
"ParentId": null,
"Children": [],
"NominalCode": ""
"NominalCode": "",
"Description": "7"
},
{
"Id": 8,
"Name": "Crocodile",
"ParentId": null,
"Children": [],
"NominalCode": ""
"NominalCode": "",
"Description": "8"
}
]
8 changes: 8 additions & 0 deletions tests/mocks/fixtures/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,62 @@ export const mockCategories = [
ParentId: null,
Children: [],
NominalCode: "",
Description: "1876023",
},
{
Id: 2,
Name: "Lion",
ParentId: null,
Children: [],
NominalCode: "",
Description: "2",
},
{
Id: 3,
Name: "Zebra",
ParentId: null,
Children: [],
NominalCode: "",
Description: "3",
},
{
Id: 4,
Name: "Hippopotamus",
ParentId: null,
Children: [],
NominalCode: "",
Description: "4",
},
{
Id: 5,
Name: "Water Buffalo",
ParentId: null,
Children: [],
NominalCode: "",
Description: "5",
},
{
Id: 6,
Name: "Giraffe",
ParentId: null,
Children: [],
NominalCode: "",
Description: "6",
},
{
Id: 7,
Name: "Cheetah",
ParentId: null,
Children: [],
NominalCode: "",
Description: "7",
},
{
Id: 8,
Name: "Crocodile",
ParentId: null,
Children: [],
NominalCode: "",
Description: "8",
},
];
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cca7ff3

Please sign in to comment.