From c2024bcdac0dd58c25231c605c3fca131276f1f2 Mon Sep 17 00:00:00 2001 From: prasasdi Date: Tue, 7 Oct 2025 00:00:58 +0700 Subject: [PATCH] post merchant and merchant's item --- test/features/merchant.feature | 12 +++++++++++- test/features/merchant_item.feature | 10 ++++++++++ test/schemas/index.ts | 10 ++++++++-- test/schemas/{ => merchant}/item.schema.ts | 14 ++++++++++++++ test/schemas/merchant/itemId.schema.ts | 5 +++++ test/schemas/{ => merchant}/merchant.schema.ts | 18 ++++++++++++++++++ test/schemas/merchant/merchantId.schema.ts | 5 +++++ 7 files changed, 71 insertions(+), 3 deletions(-) rename test/schemas/{ => merchant}/item.schema.ts (64%) create mode 100644 test/schemas/merchant/itemId.schema.ts rename test/schemas/{ => merchant}/merchant.schema.ts (60%) create mode 100644 test/schemas/merchant/merchantId.schema.ts diff --git a/test/features/merchant.feature b/test/features/merchant.feature index 991f933..b04e68d 100644 --- a/test/features/merchant.feature +++ b/test/features/merchant.feature @@ -1,5 +1,15 @@ Feature: Manage Merchant + Scenario: Add Merchant geolocation + Given tokenFromRegister exists + When I prepare a POST request to "/admin/merchants" + When I set a bearer authentication header with tokenFromRegister value + And I use postMerchantSchema payload + And send + Then the response should be 201 + And the response body matches the merchantId schema + And save the "body.merchantId" value as addedMerchantId + Scenario: Get Merchants with default Parameter Given tokenFromRegister exists When I prepare a GET request to "/admin/merchants?limit=5&offset=0" @@ -47,7 +57,7 @@ Feature: Manage Merchant Scenario: Get Small Restaurant Merchants Given tokenFromRegister exists - When I prepare a GET request to "/admin/merchants?createdAt=asc&limit=5&offset=0" + When I prepare a GET request to "/admin/merchants?createdAt=desc&limit=5&offset=0" When I set a bearer authentication header with tokenFromRegister value And send Then the response should be 200 diff --git a/test/features/merchant_item.feature b/test/features/merchant_item.feature index 70f33d7..30042b8 100644 --- a/test/features/merchant_item.feature +++ b/test/features/merchant_item.feature @@ -1,5 +1,15 @@ Feature: Manage Merchant Items + Scenario: Add Merchant geolocation + Given tokenFromRegister exists + When I prepare a POST request to "/admin/merchants/addedMerchantId/items" + When I set a bearer authentication header with tokenFromRegister value + And I use postItemSchema payload + And send + Then the response should be 201 + And the response body matches the merchantId schema + And save the "body.merchantId" value as addedMerchantLocation + Scenario: Get Merchant Items Given tokenFromRegister exists When I prepare a GET request to "/admin/merchants/id123abc/items" diff --git a/test/schemas/index.ts b/test/schemas/index.ts index 4a453aa..c3bbf13 100644 --- a/test/schemas/index.ts +++ b/test/schemas/index.ts @@ -1,15 +1,21 @@ import type z from "zod"; import { AuthSchema } from "./auth.schema"; import { UserSchema } from "./user.schema"; -import { MerchantSchema } from "./merchant.schema"; -import { ItemSchema } from "./item.schema"; +import { MerchantIdSchema } from "./merchant/merchantId.schema"; +import { MerchantSchema, PostMerchantSchema } from "./merchant/merchant.schema"; +import { ItemIdSchema } from "./merchant/itemId.schema"; +import { ItemSchema, PostItemSchema } from "./merchant/item.schema"; // biome-ignore lint/suspicious/noExplicitAny: we can't determine what ObjectSchema output will be type ObjectSchema = z.ZodType, any, any>; type SchemaRegistry = Record; export const schemaRegistry: SchemaRegistry = { + itemId: ItemIdSchema, + postItemSchema: PostItemSchema, item: ItemSchema, + merchantId: MerchantIdSchema, + postMerchantSchema: PostMerchantSchema, merchant: MerchantSchema, user: UserSchema, auth: AuthSchema, diff --git a/test/schemas/item.schema.ts b/test/schemas/merchant/item.schema.ts similarity index 64% rename from test/schemas/item.schema.ts rename to test/schemas/merchant/item.schema.ts index 0c3a642..7aa24f7 100644 --- a/test/schemas/item.schema.ts +++ b/test/schemas/merchant/item.schema.ts @@ -21,3 +21,17 @@ export const ItemSchema = z.object({ total: z.int(), }), }); + +export const PostItemSchema = z.object({ + itemId: z.string(), + name: z.string(), + productCategory: z.enum([ + "Beverage", + "Food", + "Snack", + "Condiments", + "Additions" + ]), + price: z.int().min(1), + imageUrl: z.url(), +}) \ No newline at end of file diff --git a/test/schemas/merchant/itemId.schema.ts b/test/schemas/merchant/itemId.schema.ts new file mode 100644 index 0000000..8e3417e --- /dev/null +++ b/test/schemas/merchant/itemId.schema.ts @@ -0,0 +1,5 @@ +import z from "zod" + +export const ItemIdSchema = z.object({ + itemId: z.string() +}) \ No newline at end of file diff --git a/test/schemas/merchant.schema.ts b/test/schemas/merchant/merchant.schema.ts similarity index 60% rename from test/schemas/merchant.schema.ts rename to test/schemas/merchant/merchant.schema.ts index 5f09085..c74522d 100644 --- a/test/schemas/merchant.schema.ts +++ b/test/schemas/merchant/merchant.schema.ts @@ -25,3 +25,21 @@ export const MerchantSchema = z.object({ total: z.int(), }), }); + +export const PostMerchantSchema = z.object({ + merchantId: z.string(), + name: z.string(), + merchantCategory: z.enum([ + "SmallRestaurant", + "MediumRestaurant", + "LargeRestaurant", + "MerchandiseRestaurant", + "BoothKiosk", + "ConvenienceStore" + ]), + imageUrl: z.url(), + location: z.object({ + lat: z.float32(), + long: z.float32(), + }), +}) \ No newline at end of file diff --git a/test/schemas/merchant/merchantId.schema.ts b/test/schemas/merchant/merchantId.schema.ts new file mode 100644 index 0000000..5ab3503 --- /dev/null +++ b/test/schemas/merchant/merchantId.schema.ts @@ -0,0 +1,5 @@ +import z from "zod"; + +export const MerchantIdSchema = z.object({ + merchantId: z.string() +}) \ No newline at end of file