-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* vending machine route * goddamnit tests * vend only in dev environment
- Loading branch information
1 parent
8d3611a
commit f04cf74
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { FastifyPluginAsync } from "fastify"; | ||
import { z } from "zod"; | ||
|
||
const postSchema = z.object({ | ||
name: z.string().min(1), | ||
imageUrl: z.string().url(), | ||
price: z.number().min(0), | ||
}); | ||
|
||
type VendingItemPostRequest = z.infer<typeof postSchema>; | ||
|
||
const vendingPlugin: FastifyPluginAsync = async (fastify, _options) => { | ||
fastify.get("/items", async (request, reply) => { | ||
reply.send({ | ||
items: [ | ||
{ | ||
rowid: 1, | ||
name: "TBD", | ||
image_url: | ||
"https://acm-brand-images.s3.amazonaws.com/square-blue.png", | ||
price: 400, | ||
calories: null, | ||
fat: null, | ||
carbs: null, | ||
fiber: null, | ||
sugar: null, | ||
protein: null, | ||
quantity: 100, | ||
locations: null, | ||
}, | ||
], | ||
}); | ||
}); | ||
fastify.post<{ Body: VendingItemPostRequest }>( | ||
"/items", | ||
{ | ||
preValidation: async (request, reply) => { | ||
await fastify.zodValidateBody(request, reply, postSchema); | ||
}, | ||
}, | ||
async (request, reply) => { | ||
reply.send({ status: "Not implemented." }); | ||
}, | ||
); | ||
}; | ||
|
||
export default vendingPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { expect, test } from "vitest"; | ||
import init from "../../src/index.js"; | ||
|
||
const app = await init(); | ||
test("Test getting events", async () => { | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/vending/items", | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
}); |