Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Thumbs.db
.hyf/score.json

# Editor and IDE settings
.vscode/
# Commit .vscode with settings to disable GitHub Copilot inline suggestions
# .vscode/
.idea/
*.iml
*.code-workspace
Expand Down Expand Up @@ -156,3 +157,7 @@ dist
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

task-2/services-solution.js

solutions/
.hyf/temp
5 changes: 0 additions & 5 deletions .hyf/score.example.json

This file was deleted.

39 changes: 39 additions & 0 deletions .hyf/task-1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

hyf_folder=$PWD
#target_folder="$PWD/../task-1"
target_folder="$PWD/../solutions/task-1"
temp_folder="$hyf_folder/temp"

mkdir "$temp_folder" 2>/dev/null

if [ ! -f "$target_folder/post.sh" ]; then
echo "post.sh not found!"
exit 1
fi
if [ ! -f "$target_folder/patch.sh" ]; then
echo "patch.sh not found!"
exit 1
fi
if [ ! -f "$target_folder/get.sh" ]; then
echo "get.sh not found!"
exit 1
fi
if [ ! -f "$target_folder/delete.sh" ]; then
echo "delete.sh not found!"
exit 1
fi

cd ..
/usr/bin/env npm install
/usr/bin/env npm start &
sleep 3

cd "$target_folder" || exit

bash post.sh >"$temp_folder/post.json" 2>/dev/null
bash patch.sh >"$temp_folder/patch.json" 2>/dev/null
bash get.sh >"$temp_folder/get.json" 2>/dev/null
bash delete.sh 2>/dev/null
bash get.sh >"$temp_folder/notfound.txt" 2>/dev/null
kill -9 $(lsof -t -i:3000)
23 changes: 13 additions & 10 deletions .hyf/test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail

# Run your test scripts here.
# Auto grade tool will execute this file within the .hyf working directory.
# The result should be stored in score.json file with the format shown below.
cat << EOF > score.json
{
"score": 0,
"pass": true,
"passingScore": 0
}
EOF
pushd ..
/usr/bin/env npm install
# Start the server
/usr/bin/env npm start &
sleep 3
npx vitest run --reporter=json --outputFile=.hyf/report.json
popd || exit
} >/dev/null

PASSING_SCORE=50 /usr/bin/env node tester.js

# Kill the server
kill -9 $(lsof -t -i:3000)
55 changes: 55 additions & 0 deletions .hyf/tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import fs from 'fs/promises';
import path from 'path';

const __dirname = import.meta.dirname;
const reportPath = path.join(__dirname, 'report.json');

try {
const reportContent = await fs.readFile(reportPath, 'utf-8');
await fs.unlink(reportPath);

const { testResults } = JSON.parse(reportContent);
let maxPoints = 0;
let earnedPoints = 0;
let passedCount = 0;
let failedCount = 0;

console.log('Vitest unit test results:\n');

const passingScore = Number(process.env.PASSING_SCORE || 50);

for (const result of testResults) {
for (const { title, status } of result.assertionResults) {
const match = title.match(/^\[(\d+)]/);
const points = match ? Number(match[1]) || 1 : 1;
maxPoints += points;
let icon;
if (status === 'passed') {
icon = '✅';
passedCount += 1;
earnedPoints += points;
} else {
icon = '❌';
failedCount += 1;
}
console.log(`${icon} ${title}`);
}
}

console.log(`\nTotal passed: ${passedCount}`);
console.log(`Total failed: ${failedCount}`);

const totalScore = Math.round((earnedPoints / maxPoints) * 100);

const results = {
score: totalScore,
pass: totalScore >= passingScore,
passingScore: passingScore,
};

await fs.writeFile('score.json', JSON.stringify(results, null, 2));
process.exit(0);
} catch (error) {
console.error('Error parsing report JSON:', error);
process.exit(1);
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
// "editor.inlineSuggest.enabled": false
// "github.copilot.enable": {
// "javascript": false
// }
}
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
# Core program week X assignment
HackYourFuture <Track> week X assignment

Core Program week 9 assignment

## Implementation Instructions
Provide clear instructions on how trainees should implement the tasks.

### Task 1
Instructions for Task 1

In this task you will practice reading API documentation and using **curl**. The API reference you need is in the [GUIDE.md](task-1/GUIDE.md) file. Read it carefully and construct your own **curl** requests from the endpoint details.

Before you start, open a terminal in the repository root and start the server with `npm start`. Keep it running while you work.

Create your scripts inside the `task-1` folder and run each script with `bash` after you finish it.

1. Create a `post.sh` bash script. It must send a `POST` request with **curl** to create a new user. Use these values in the JSON body:

| Field | Value |
| ---------- | -------------------- |
| name | John Doe |
| email | john.doe@example.com |
| role | user |
| active | true |
| department | Engineering |

Run the script. Record the `id` in the response. You will use it in the next steps.

2. The email address from the previous step mistakenly included an extra dot between first and last name. We will correct it here. Create a `patch.sh` bash script. It must send a **curl** `PATCH` request to update the email address for the user you just created. Fix the email by removing the extra dot, changing it to `johndoe@example.com`. Note that in general, a `PATCH` request should include only the field you are updating. In our case this is the `email` field only.

3. Create a `get.sh` script. It must send a **curl** `GET` request to fetch the user by `id`. Verify the response contains the updated email.

4. Create a `delete.sh` script. It must send a **curl** `DELETE` request for the same `id` to remove the user.

5. Re-run the `get.sh` script. The response should now be "User not found".

When you have completed all steps, stop the server with `Ctrl-C`.

### Task 2

Instructions for Task 2

...

Loading
Loading