Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e1235d3
relocate frontend and setup backend environment
minhngo3818 Aug 13, 2022
7b248c4
reorganize directories
minhngo3818 Aug 13, 2022
2b66bc7
Merge branch 'main' of https://github.com/Computer-Science-Club-OCC/C…
minhngo3818 Aug 14, 2022
39390b2
update, add gitignore, modify workflow
minhngo3818 Aug 14, 2022
677be79
minor updates
minhngo3818 Aug 16, 2022
3c4e74f
setup axios & eslint-prettier for backend
minhngo3818 Aug 16, 2022
f9dac7b
setup jest for testing
minhngo3818 Aug 16, 2022
8d1b3f6
setup git pages
minhngo3818 Aug 18, 2022
93c0f65
completed backend setup & add axios for api
minhngo3818 Aug 27, 2022
15a5a8b
setup testing environment
minhngo3818 Aug 27, 2022
4223df9
Merge 'main' into setup-backend-env client
minhngo3818 Aug 29, 2022
70be5e0
fix bug
minhngo3818 Aug 29, 2022
583eea6
re-allocate diretories
minhngo3818 Aug 29, 2022
61784a9
config jest, add dummy test & naming convention
minhngo3818 Aug 30, 2022
77724ad
change it into test for readability
minhngo3818 Aug 31, 2022
1a3581b
add tags model
minhngo3818 Aug 31, 2022
016e321
update .env file
minhngo3818 Aug 31, 2022
8ac0107
fix typo
minhngo3818 Aug 31, 2022
beddac4
remove unnecessary code
minhngo3818 Aug 31, 2022
3b7cad7
replace handleError with console.log()
minhngo3818 Aug 31, 2022
ba3b027
add imageSchema to eventSchema
minhngo3818 Aug 31, 2022
2d332ac
refactor description into detail
minhngo3818 Aug 31, 2022
82e51fb
remove unused code in activity
minhngo3818 Sep 1, 2022
20fb051
add external gitignore
minhngo3818 Sep 1, 2022
74eec15
add new line in external gitignore
minhngo3818 Sep 1, 2022
0c05056
remove body parser due to express v4
minhngo3818 Sep 2, 2022
01b6456
use built-in express parser
minhngo3818 Sep 2, 2022
a756024
add controllers, framework, tags-route
minhngo3818 Sep 2, 2022
0d8929b
Fixed broken workflow bc/ of refactor
KHVBui Sep 2, 2022
80c3b7c
add rules, remove unused plugins, add format:diff
minhngo3818 Sep 3, 2022
214b3db
comment unused imports & format
minhngo3818 Sep 3, 2022
d6831da
Merge pull request #70 from Computer-Science-Club-OCC/bug-fix-workflo…
minhngo3818 Sep 3, 2022
e4b5f4f
add import plugin
minhngo3818 Sep 3, 2022
41828a3
Merge branch 'setup-backend-env' of https://github.com/Computer-Scien…
minhngo3818 Sep 3, 2022
7b6bf77
add plugin n
minhngo3818 Sep 3, 2022
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
3 changes: 1 addition & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ on:
workflow_dispatch:

jobs:
build_test:

client:
runs-on: ${{ matrix.os }}
env:
CI: false
Expand Down
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Ignoring packages
*.zip
*.tar.gz
*.rar

# Ignore vscode
.vscode/

# Ignore JetBrain IDE
.idea/

# Ignore sublime files
*.sublime-workspace

# Ignore package-lock.json
package-lock.json
package.json

# Ignore dependencies generated in root
# dependencies
/node_modules
/.pnp
Expand Down
3 changes: 3 additions & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# NOTES: This file will not be included in actual deployment !!
PORT=8000
DATABASE_URI=mongodb://localhost:27017/cs_club
13 changes: 13 additions & 0 deletions backend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": ["standard", "plugin:jest/recommended", "prettier"],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {}
}
23 changes: 23 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build
/static

# misc
.env
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
6 changes: 6 additions & 0 deletions backend/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": false
}
34 changes: 34 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const express = require("express")
const app = express()
const mongoose = require("mongoose")
const multer = require("multer")
const PORT = process.env.PORT || 8000
require("dotenv/config")

// Connect datbase and create collection
mongoose
.connect(
process.env.DATABASE_URI,
{ useNewUrlParser: true },
{ useUnifiedTopology: true },
() => console.log("Connected to datbase!")
)
.catch((error) => {
console.log(error)
})

// User parsing middleware

// Import Routes
const eventsRoute = require("./routes/events/events-route")
const projectsRoute = require("./routes/projects/projects-route")
const tutorialsRoute = require("./routes/tutorials/tutorials-route")
const readingsRoute = require("./routes/readings/readings-route")
const organizationsRoute = require("./routes/organizations/orgs-route")

// Use Routes

// Run server
app.listen(PORT, () => {
console.log(`Running backend server on: http://localhost:${PORT}`)
})
195 changes: 195 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

module.exports = {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\tonyh\\AppData\\Local\\Temp\\jest",

// Automatically clear mock calls, instances, contexts and results before every test
// clearMocks: false,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information shoul d be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
// coverageDirectory: undefined,

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: true,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: undefined,

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
testEnvironment: "jest-environment-node",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// A map from regular expressions to paths to transformers
// transform: undefined,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\",
// "\\.pnp\\.[^\\\\]+$"
// ],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,
}
35 changes: 35 additions & 0 deletions backend/models/db-test-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const mongoose = require("mongoose")
const { MongoMemoryServer } = require("mongodb-memory-server")

let mongod = undefined

// Setup database actions for testing schemas
// Connect to database
module.exports.connect = async () => {
mongod = await MongoMemoryServer.create()
const uri = mongod.getUri()

mongoose.connect(uri, {
dbName: "cs_club_test",
useNewUrlParser: true,
useUnifiedTopology: true,
maxPoolSize: 10,
})
}

// Disconnect
module.exports.closeDatabase = async () => {
await mongoose.connection.dropDatabase()
await mongoose.connection.close()
await mongod.stop()
}

// Clean up database
module.exports.clearDatabase = async () => {
if (mongod) {
const collections = mongoose.connection.collections
for (const key in collections) {
collections[key].deleteMany()
}
}
}
24 changes: 24 additions & 0 deletions backend/models/events/events-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const mongoose = require("mongoose")
const { Schema } = mongoose
const image = require("../image/image-model")
const imageSchema = mongoose.model("image").schema

// Add your code here
const eventSchema = new Schema({
title: {
type: String,
required: true,
},
detail: {
type: String,
required: true,
},
location: String,
date: {
type: Date,
default: Date.now,
},
images: [imageSchema],
})

module.exports = mongoose.model("events", eventSchema)
17 changes: 17 additions & 0 deletions backend/models/events/events-model.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require("mongoose")
const eventsModel = require("./events-model")
const db = require("../db-test-setup")

// Define test instances here

// Database for testing
beforeAll(async () => await db.connect())
afterEach(async () => await db.clearDatabase())
afterAll(async () => await db.closeDatabase())

// Add your test here
describe("Events Model Tests", () => {
test("Dummy test", () => {
expect(true).toBe(true)
})
})
Loading