-
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.
feat: Farm category toggles, test and build on CI (#22)
- Loading branch information
1 parent
7a84921
commit a08c179
Showing
6 changed files
with
153 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
# Ref: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs#example-using-npm | ||
# Did not commit package-lock.json file therefore cannot use `npm ci` | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "22.x" | ||
- name: Install dependencies | ||
run: npm install | ||
- run: npm run build --if-present | ||
- run: npm test |
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 |
---|---|---|
|
@@ -46,6 +46,11 @@ Standard build | |
Format the code | ||
|
||
`npm run prettier` | ||
🧪 | ||
|
||
### Test app | ||
|
||
`npm run test` | ||
|
||
### Run app 🚀 | ||
|
||
|
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,18 @@ | ||
export const compareExact = (template, obj) => { | ||
let templateKeys = Object.keys(template); | ||
|
||
if (templateKeys.length === Object.keys(obj).length) { | ||
return templateKeys.every( | ||
(key) => obj.hasOwnProperty(key) && obj[key] === template[key] | ||
); | ||
} | ||
return false; | ||
}; | ||
|
||
export const compareSparse = (template, obj) => { | ||
let templateKeys = Object.keys(template); | ||
|
||
return templateKeys.every( | ||
(key) => obj.hasOwnProperty(key) && obj[key] === template[key] | ||
); | ||
}; |
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,59 @@ | ||
import { compareExact, compareSparse } from "../src/utils.js"; | ||
import assert from "node:assert/strict"; | ||
import { test } from "node:test"; | ||
|
||
test(`compareExact() of equal objects - return true`, () => { | ||
const template = { | ||
private: false, | ||
public: true, | ||
}; | ||
const obj = { private: false, public: true }; | ||
|
||
assert.equal(compareExact(template, obj), true); | ||
}); | ||
|
||
test(`compareExact() of non equal objects - return false`, () => { | ||
const template = { | ||
private: false, | ||
public: true, | ||
}; | ||
const obj = { private: true, public: true }; | ||
|
||
assert.equal(compareExact(template, obj), false); | ||
}); | ||
|
||
test(`compareSparse() contains equal key, values - return true`, () => { | ||
const template = { | ||
bookable: true, | ||
shop: true, | ||
}; | ||
|
||
const obj = { | ||
alpacaSales: true, | ||
alpacaWalking: true, | ||
bookable: true, | ||
shop: true, | ||
overnightStay: true, | ||
studServices: false, | ||
}; | ||
|
||
assert.equal(compareSparse(template, obj), true); | ||
}); | ||
|
||
test(`compareSparse() contains non-equal key, values - return false`, () => { | ||
const template = { | ||
bookable: true, | ||
shop: true, | ||
}; | ||
|
||
const obj = { | ||
alpacaSales: true, | ||
alpacaWalking: true, | ||
bookable: false, | ||
shop: true, | ||
overnightStay: true, | ||
studServices: false, | ||
}; | ||
|
||
assert.equal(compareSparse(template, obj), false); | ||
}); |