Skip to content

Commit cf6c779

Browse files
Initial commit
0 parents  commit cf6c779

26 files changed

+8275
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/devcontainers/images/tree/main/src/javascript-node
3+
{
4+
"name": "JavaScript recipe app with GitHub Codespaces",
5+
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye",
6+
"hostRequirements": {
7+
"cpus": 4
8+
},
9+
"waitFor": "onCreateCommand",
10+
"updateContentCommand": "npm install",
11+
"postCreateCommand": "",
12+
"postAttachCommand": {
13+
"server": "npm start"
14+
},
15+
16+
// Configure tool-specific properties.
17+
"customizations": {
18+
// Configure properties specific to VS Code.
19+
"vscode": {
20+
// Add the IDs of extensions you want installed when the container is created.
21+
"extensions": ["GitHub.copilot"]
22+
}
23+
},
24+
25+
"features": {
26+
"ghcr.io/devcontainers/features/github-cli:1": {}
27+
},
28+
29+
"portsAttributes": {
30+
"3000": {
31+
"label": "Recipe App",
32+
"onAutoForward": "openPreview"
33+
}
34+
},
35+
36+
"forwardPorts": [3000]
37+
}

.github/pull_request_template.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!--
2+
This repository does not accept pull requests through the normal process.
3+
PRs without the 'pre-approved' label will be automatically closed. If you are learning about this repository
4+
and are following the steps, then you need to make changes in your own account.
5+
6+
If you need this PR to be merged, you have two options:
7+
8+
1. Label this PR with the 'pre-approved' label if you have admin or enough privileges
9+
10+
or
11+
12+
2. Tag phazonoverload to take a look
13+
14+
Thank you for your understanding!
15+
-->
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Auto close pull requests
2+
on:
3+
pull_request_target:
4+
types: [opened, labeled, unlabeled, reopened]
5+
6+
jobs:
7+
auto_close:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Close PR if not pre-approved
14+
if: ${{ !(contains(github.event.pull_request.labels.*.name, 'pre-approved')) && !(contains(github.event.pull_request.body, '@phazonoverload')) }}
15+
run: |
16+
MESSAGE="This repository doesn't accept pull requests. Please fork the repository and make changes there. If you really need this PR to be merged you must be an admin and label this pr with the 'pre-approved' label *or* tag Kevin Lewis (\`@phazonoverload\`) to take a look."
17+
# TODO: Update repo name
18+
gh pr close ${{ github.event.pull_request.number }} --repo education/codespaces-project-template-js --comment "$MESSAGE"
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# Snowpack dependency directory (https://snowpack.dev/)
45+
web_modules/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional stylelint cache
57+
.stylelintcache
58+
59+
# Optional REPL history
60+
.node_repl_history
61+
62+
# Output of 'npm pack'
63+
*.tgz
64+
65+
# Yarn Integrity file
66+
.yarn-integrity
67+
68+
# dotenv environment variable files
69+
.env
70+
.env.*
71+
!.env.example
72+
73+
# parcel-bundler cache (https://parceljs.org/)
74+
.cache
75+
.parcel-cache
76+
77+
# Next.js build output
78+
.next
79+
out
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and not Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# vuepress v2.x temp and cache directory
95+
.temp
96+
.cache
97+
98+
# Sveltekit cache directory
99+
.svelte-kit/
100+
101+
# vitepress build output
102+
**/.vitepress/dist
103+
104+
# vitepress cache directory
105+
**/.vitepress/cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# Firebase cache directory
120+
.firebase/
121+
122+
# TernJS port file
123+
.tern-port
124+
125+
# Stores VSCode versions used for testing VSCode extensions
126+
.vscode-test
127+
128+
# yarn v3
129+
.pnp.*
130+
.yarn/*
131+
!.yarn/patches
132+
!.yarn/plugins
133+
!.yarn/releases
134+
!.yarn/sdks
135+
!.yarn/versions
136+
137+
# Vite logs files
138+
vite.config.js.timestamp-*
139+
vite.config.ts.timestamp-*
140+
141+
*.sqlite

CODE_OF_CONDUCT.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Microsoft Open Source Code of Conduct
2+
3+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4+
5+
Resources:
6+
7+
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8+
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9+
- Contact [[email protected]](mailto:[email protected]) with questions or concerns

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

SECURITY.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.7 BLOCK -->
2+
3+
## Security
4+
5+
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6+
7+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
8+
9+
## Reporting Security Issues
10+
11+
**Please do not report security vulnerabilities through public GitHub issues.**
12+
13+
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
14+
15+
If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
16+
17+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
18+
19+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20+
21+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22+
* Full paths of source file(s) related to the manifestation of the issue
23+
* The location of the affected source code (tag/branch/commit or direct URL)
24+
* Any special configuration required to reproduce the issue
25+
* Step-by-step instructions to reproduce the issue
26+
* Proof-of-concept or exploit code (if possible)
27+
* Impact of the issue, including how an attacker might exploit the issue
28+
29+
This information will help us triage your report more quickly.
30+
31+
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
32+
33+
## Preferred Languages
34+
35+
We prefer all communications to be in English.
36+
37+
## Policy
38+
39+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
40+
41+
<!-- END MICROSOFT SECURITY.MD BLOCK -->

__tests__/database.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { getTestDbConnection, initializeTestDb } = require('./test-database');
2+
3+
describe('Database Operations', () => {
4+
let db;
5+
6+
beforeEach(async () => {
7+
db = await initializeTestDb();
8+
});
9+
10+
afterEach(async () => {
11+
if (db) {
12+
await db.close();
13+
}
14+
});
15+
16+
test('should create recipes table', async () => {
17+
const tableInfo = await db.all("SELECT name FROM sqlite_master WHERE type='table' AND name='recipes'");
18+
expect(tableInfo).toHaveLength(1);
19+
expect(tableInfo[0].name).toBe('recipes');
20+
});
21+
22+
test('should insert a new recipe', async () => {
23+
const title = 'Test Recipe';
24+
const ingredients = 'Test ingredients';
25+
const method = 'Test method';
26+
27+
await db.run('INSERT INTO recipes (title, ingredients, method) VALUES (?, ?, ?)',
28+
[title, ingredients, method]);
29+
30+
const recipe = await db.get('SELECT * FROM recipes WHERE title = ?', [title]);
31+
expect(recipe).toBeDefined();
32+
expect(recipe.title).toBe(title);
33+
expect(recipe.ingredients).toBe(ingredients);
34+
expect(recipe.method).toBe(method);
35+
});
36+
});

__tests__/routes.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const request = require('supertest');
2+
const express = require('express');
3+
const routes = require('../src/routes');
4+
const { initializeTestDb } = require('./test-database');
5+
6+
// Mock the database module to use test database
7+
jest.mock('../src/database', () => ({
8+
getDbConnection: () => require('./test-database').getTestDbConnection()
9+
}));
10+
11+
// Simple app setup for testing
12+
function createTestApp() {
13+
const app = express();
14+
app.use(express.json());
15+
app.use(express.urlencoded({ extended: true }));
16+
17+
// Simple mock for res.render
18+
app.use((req, res, next) => {
19+
res.render = (view, locals) => res.json({ view, locals });
20+
next();
21+
});
22+
23+
app.use('/', routes);
24+
return app;
25+
}
26+
27+
describe('Routes', () => {
28+
let app;
29+
let db;
30+
31+
beforeEach(async () => {
32+
app = createTestApp();
33+
db = await initializeTestDb();
34+
});
35+
36+
afterEach(async () => {
37+
if (db) {
38+
await db.close();
39+
}
40+
});
41+
42+
test('GET / should return 200', async () => {
43+
const response = await request(app).get('/');
44+
expect(response.status).toBe(200);
45+
expect(response.body.view).toBe('home');
46+
});
47+
48+
test('POST /recipes should create a new recipe', async () => {
49+
const newRecipe = {
50+
title: 'New Test Recipe',
51+
ingredients: 'New test ingredients',
52+
method: 'New test method'
53+
};
54+
55+
const response = await request(app)
56+
.post('/recipes')
57+
.send(newRecipe);
58+
59+
expect(response.status).toBe(302); // Redirect status
60+
expect(response.headers.location).toBe('/recipes');
61+
62+
// Verify recipe was created
63+
const recipe = await db.get('SELECT * FROM recipes WHERE title = ?', [newRecipe.title]);
64+
expect(recipe).toBeDefined();
65+
expect(recipe.title).toBe(newRecipe.title);
66+
});
67+
});

0 commit comments

Comments
 (0)