diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 0cfe1340..06d14676 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -85,6 +85,11 @@ jobs: env: ACT: ${{ env.ACT }} + - name: Run k6 foundations TS tests + run: ./scripts/run-tests.sh -t **/k6/foundations/*.ts -u http://localhost:3333 + env: + ACT: ${{ env.ACT }} + - name: Run k6 internal tests run: ./scripts/run-tests.sh -t **/k6/internal/*.js -u http://localhost:3333 env: diff --git a/k6/foundations/01.basic.ts b/k6/foundations/01.basic.ts new file mode 100644 index 00000000..38dc07c1 --- /dev/null +++ b/k6/foundations/01.basic.ts @@ -0,0 +1,42 @@ +import http from 'k6/http'; +import { check, sleep } from 'k6'; + +const BASE_URL: string = __ENV.BASE_URL || 'http://localhost:3333'; + +export const options = { + vus: 5, + duration: '5s', +}; + +interface Restrictions { + maxCaloriesPerSlice: number; + mustBeVegetarian: boolean; + excludedIngredients: string[]; + excludedTools: string[]; + maxNumberOfToppings: number; + minNumberOfToppings: number; +} + +export default function (): void { + const restrictions: Restrictions = { + maxCaloriesPerSlice: 500, + mustBeVegetarian: false, + excludedIngredients: ["pepperoni"], + excludedTools: ["knife"], + maxNumberOfToppings: 6, + minNumberOfToppings: 2, + }; + + const res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), { + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'token abcdef0123456789', + }, + }); + + check(res, { "status is 200": (res) => res.status === 200 }); + + const responseBody = res.json() as { pizza: { name: string; ingredients: string[] } }; + console.log(`${responseBody.pizza.name} (${responseBody.pizza.ingredients.length} ingredients)`); + sleep(1); +}