-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cd8e9b
commit af53ae5
Showing
8 changed files
with
4,084 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# .github/workflows/main.yml | ||
name: Run Jest Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: "20.x" | ||
- run: npm install | ||
- run: npm run ghworkflowtest -- --ci --reporters=default --reporters=jest-junit | ||
- name: update Airtable | ||
if: always() | ||
run: node ./.scripts/main.js JS ${{github.actor}} https://github.com/${{github.repository}} |
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,130 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* |
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,85 @@ | ||
const axios = require("axios"); | ||
const fs = require("fs"); | ||
const { argv } = require("process"); | ||
const xml2js = require("xml2js"); | ||
|
||
// Constants and configuration | ||
const TOPIC = argv[2]; | ||
const STUDENT_GITHUB = argv[3]; | ||
const STUDENT_REPO = argv[4]; | ||
const JEST_REPORT_PATH = "./junit.xml"; | ||
|
||
// Airtable API functions | ||
const airtableApiServer = axios.create({ | ||
baseURL: `https://airtable-be.vercel.app/`, | ||
}); | ||
|
||
// Jest report parsing | ||
function parseJestReport(xmlContent) { | ||
return new Promise((resolve, reject) => { | ||
xml2js.parseString(xmlContent, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
const testsuites = result.testsuites; | ||
const totalTests = parseInt(testsuites.$.tests); | ||
const failedTests = parseInt(testsuites.$.failures); | ||
const passedTests = totalTests - failedTests; | ||
const grade = (passedTests / totalTests) * 100; | ||
|
||
resolve({ totalTests, passedTests, failedTests, grade }); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
const sendDataToServer = async ( | ||
passedTests, | ||
failedTests, | ||
grade, | ||
studentGitHub, | ||
studentRepo | ||
) => { | ||
try { | ||
await airtableApiServer | ||
.post("/", { | ||
passedTests, | ||
failedTests, | ||
grade, | ||
studentGitHub, | ||
studentRepo, | ||
topic: TOPIC, | ||
}) | ||
.then((response) => console.log("Sent Data Successfully")); | ||
} catch (error) { | ||
console.log("error in sending data to server", error); | ||
} | ||
}; | ||
|
||
// Main function | ||
async function main() { | ||
try { | ||
const jestResults = fs.readFileSync(JEST_REPORT_PATH, "utf8"); | ||
const { totalTests, passedTests, failedTests, grade } = | ||
await parseJestReport(jestResults); | ||
|
||
console.log(`Total tests: ${totalTests}`); | ||
console.log(`Passed tests: ${passedTests}`); | ||
console.log(`Failed tests: ${failedTests}`); | ||
console.log(`Grade: ${grade.toFixed(2)}%`); | ||
|
||
await sendDataToServer( | ||
passedTests, | ||
failedTests, | ||
grade.toFixed(2), | ||
STUDENT_GITHUB, | ||
STUDENT_REPO | ||
); | ||
} catch (error) { | ||
console.error("An error occurred:", error.message); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
// Run the main function | ||
main(); |
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 |
---|---|---|
@@ -1 +1,24 @@ | ||
# JS-Iteration-Over-Objects-Part2 | ||
# JS-Iteration-Over-Objects-Part2 | ||
|
||
## Instructions | ||
|
||
- Fork and clone [this repository](https://github.com/JoinCODED/JS-Iteration-Over-Objects-Part2) to your `Development` folder. | ||
- ```bash | ||
git clone [email protected]:<your_username>/JS-Iteration-Over-Objects-Part2.git | ||
``` | ||
|
||
### Running The Tests | ||
|
||
- Install all the requirements: | ||
1. Navigate to the project root (you'll find a file called `package.json` there). | ||
2. Install the requirements with the following command: | ||
```bash | ||
npm install | ||
``` | ||
3. Run the tests | ||
```bash | ||
npm test | ||
``` | ||
4. This command will run the testing file and test your code to make sure it has all the required features. | ||
5. You know you're done when your code passes all the tests! | ||
6. Go to the Actions tab and make sure to enable the github actions! |
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,114 @@ | ||
const students = [ | ||
{ | ||
id: 1, | ||
name: "Alice", | ||
courses: ["Math", "Science", "History"], | ||
}, | ||
{ | ||
id: 2, | ||
name: "Bob", | ||
courses: ["History", "English", "Math", "Art"], | ||
}, | ||
{ | ||
id: 3, | ||
name: "Charlie", | ||
courses: ["Science", "English", "Music"], | ||
}, | ||
{ | ||
id: 4, | ||
name: "David", | ||
courses: ["Math", "History", "Art", "PE"], | ||
}, | ||
{ | ||
id: 5, | ||
name: "Eva", | ||
courses: ["Science", "Math", "Music"], | ||
}, | ||
{ | ||
id: 6, | ||
name: "Frank", | ||
courses: ["English", "Art"], | ||
}, | ||
{ | ||
id: 7, | ||
name: "Grace", | ||
courses: ["Math", "Science", "English", "Music"], | ||
}, | ||
{ | ||
id: 8, | ||
name: "Helen", | ||
courses: ["History", "Art", "PE"], | ||
}, | ||
{ | ||
id: 9, | ||
name: "Ivy", | ||
courses: ["Science", "English", "Art"], | ||
}, | ||
{ | ||
id: 10, | ||
name: "Jack", | ||
courses: ["Math", "History", "Music"], | ||
}, | ||
]; | ||
|
||
// 1) Using `getStudentName` that accepts an argument of `student` object, return the student name | ||
function getStudentName(student) { | ||
// write your code here... | ||
} | ||
// console.log(getStudentName(students[0])) | ||
|
||
// 2) Using `getCourse` function that accepts a `student` object and `courseIndex` return the course at the specified course index in the student's courses array | ||
|
||
function getCourse(student, courseIndex) { | ||
// write your code here... | ||
} | ||
// console.log(getCourse(students[4], 2)); // Outputs: Music | ||
|
||
// 3) Using `addCourseToStudent` function that accepts a `student` object and `course` string, it will add the course to the student's courses array, and return the `student` object | ||
function addCourseToStudent(student, course) { | ||
// write your code here... | ||
} | ||
// console.log(addCourseToStudent(students[7], "Physics")); | ||
|
||
// 4) Using `countCourses` function that accept a `student` object, return the number of courses the student in enrolled in | ||
function countCourses(student) { | ||
// write your code here... | ||
} | ||
// console.log(countCourses(students[1])); // Outputs: 4 | ||
|
||
// 🌶️🌶️ | ||
// 5) Using `listAllCourses` function that accepts an array of `students`, return an array of all unique courses names across all students | ||
function listAllCourses(students) { | ||
// write your code here... | ||
} | ||
// console.log(listAllCourses(students)); | ||
|
||
// 6) Using `removeCourseFromStudent` function that accepts a `student` object and `course` string, remove the `course` from the student's courses array,, and return the `student` object. | ||
function removeCourseFromStudent(student, course) { | ||
// write your code here... | ||
} | ||
// console.log(removeCourseFromStudent(students[6], "Science")); | ||
|
||
// 7) Using `findStudentById` function that accepts a `studentId` and an array of student objects `students`, return the student object with the matching id. | ||
function findStudentById(studentId, students) { | ||
// write your code here... | ||
} | ||
// console.log(findStudentById(10, students)); | ||
|
||
// 🌶️🌶️🌶️ | ||
// 8) Using `getStudentsByCourse` function that accepts a `course` string and an array of student objects `students`, return an array of student objects who are enrolled in the specified course | ||
function getStudentsByCourse(course, students) { | ||
// write your code here... | ||
} | ||
// console.log(getStudentsByCourse("Music", students)); | ||
|
||
module.exports = { | ||
getStudentName, | ||
getCourse, | ||
addCourseToStudent, | ||
countCourses, | ||
listAllCourses, | ||
removeCourseFromStudent, | ||
findStudentById, | ||
getStudentsByCourse, | ||
}; |
Oops, something went wrong.