From f114e1d13786f05497a28fcaec15824570889b22 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 4 Jan 2024 18:30:27 +0000 Subject: [PATCH] Remove unused test example --- tests/ml-powered-queries-repo/add-note.js | 21 ------ tests/ml-powered-queries-repo/app.js | 68 -------------------- tests/ml-powered-queries-repo/index.js | 7 -- tests/ml-powered-queries-repo/logger.js | 5 -- tests/ml-powered-queries-repo/models/note.js | 8 --- tests/ml-powered-queries-repo/models/user.js | 6 -- tests/ml-powered-queries-repo/notes-api.js | 44 ------------- tests/ml-powered-queries-repo/read-notes.js | 37 ----------- tests/ml-powered-queries-repo/users-api.js | 25 ------- 9 files changed, 221 deletions(-) delete mode 100644 tests/ml-powered-queries-repo/add-note.js delete mode 100644 tests/ml-powered-queries-repo/app.js delete mode 100644 tests/ml-powered-queries-repo/index.js delete mode 100644 tests/ml-powered-queries-repo/logger.js delete mode 100644 tests/ml-powered-queries-repo/models/note.js delete mode 100644 tests/ml-powered-queries-repo/models/user.js delete mode 100644 tests/ml-powered-queries-repo/notes-api.js delete mode 100644 tests/ml-powered-queries-repo/read-notes.js delete mode 100644 tests/ml-powered-queries-repo/users-api.js diff --git a/tests/ml-powered-queries-repo/add-note.js b/tests/ml-powered-queries-repo/add-note.js deleted file mode 100644 index ee7c735f95..0000000000 --- a/tests/ml-powered-queries-repo/add-note.js +++ /dev/null @@ -1,21 +0,0 @@ -const mongoose = require('mongoose'); - -Logger = require('./logger').Logger; -Note = require('./models/note').Note; - -(async () => { - if (process.argv.length != 5) { - Logger.log("Creates a private note. Usage: node add-note.js <body>") - return; - } - - // Open the default mongoose connection - await mongoose.connect('mongodb://localhost:27017/notes', { useFindAndModify: false }); - - const [userToken, title, body] = process.argv.slice(2); - await Note.create({ title, body, userToken }); - - Logger.log(`Created private note with title ${title} and body ${body} belonging to user with token ${userToken}.`); - - await mongoose.connection.close(); -})(); diff --git a/tests/ml-powered-queries-repo/app.js b/tests/ml-powered-queries-repo/app.js deleted file mode 100644 index 53c2f10e7b..0000000000 --- a/tests/ml-powered-queries-repo/app.js +++ /dev/null @@ -1,68 +0,0 @@ -const bodyParser = require('body-parser'); -const express = require('express'); -const mongoose = require('mongoose'); - -const notesApi = require('./notes-api'); -const usersApi = require('./users-api'); - -const addSampleData = module.exports.addSampleData = async () => { - const [userA, userB] = await User.create([ - { - name: "A", - token: "tokenA" - }, - { - name: "B", - token: "tokenB" - } - ]); - - await Note.create([ - { - title: "Public note belonging to A", - body: "This is a public note belonging to A", - isPublic: true, - ownerToken: userA.token - }, - { - title: "Public note belonging to B", - body: "This is a public note belonging to B", - isPublic: true, - ownerToken: userB.token - }, - { - title: "Private note belonging to A", - body: "This is a private note belonging to A", - ownerToken: userA.token - }, - { - title: "Private note belonging to B", - body: "This is a private note belonging to B", - ownerToken: userB.token - } - ]); -} - -module.exports.startApp = async () => { - // Open the default mongoose connection - await mongoose.connect('mongodb://mongo:27017/notes', { useFindAndModify: false }); - // Drop contents of DB - mongoose.connection.dropDatabase(); - // Add some sample data - await addSampleData(); - - const app = express(); - - app.use(bodyParser.json()); - app.use(bodyParser.urlencoded()); - - app.get('/', async (_req, res) => { - res.send('Hello World'); - }); - - app.use('/api/notes', notesApi.router); - app.use('/api/users', usersApi.router); - - app.listen(3000); - Logger.log('Express started on port 3000'); -}; diff --git a/tests/ml-powered-queries-repo/index.js b/tests/ml-powered-queries-repo/index.js deleted file mode 100644 index aaecbe83b6..0000000000 --- a/tests/ml-powered-queries-repo/index.js +++ /dev/null @@ -1,7 +0,0 @@ -const startApp = require('./app').startApp; - -Logger = require('./logger').Logger; -Note = require('./models/note').Note; -User = require('./models/user').User; - -startApp(); diff --git a/tests/ml-powered-queries-repo/logger.js b/tests/ml-powered-queries-repo/logger.js deleted file mode 100644 index b8992c611c..0000000000 --- a/tests/ml-powered-queries-repo/logger.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports.Logger = class { - log(message, ...objs) { - console.log(message, objs); - } -}; diff --git a/tests/ml-powered-queries-repo/models/note.js b/tests/ml-powered-queries-repo/models/note.js deleted file mode 100644 index d2cecee123..0000000000 --- a/tests/ml-powered-queries-repo/models/note.js +++ /dev/null @@ -1,8 +0,0 @@ -const mongoose = require('mongoose'); - -module.exports.Note = mongoose.model('Note', new mongoose.Schema({ - title: String, - body: String, - ownerToken: String, - isPublic: Boolean -})); diff --git a/tests/ml-powered-queries-repo/models/user.js b/tests/ml-powered-queries-repo/models/user.js deleted file mode 100644 index ac0545fb8b..0000000000 --- a/tests/ml-powered-queries-repo/models/user.js +++ /dev/null @@ -1,6 +0,0 @@ -const mongoose = require('mongoose'); - -module.exports.User = mongoose.model('User', new mongoose.Schema({ - name: String, - token: String -})); diff --git a/tests/ml-powered-queries-repo/notes-api.js b/tests/ml-powered-queries-repo/notes-api.js deleted file mode 100644 index d11a0f4346..0000000000 --- a/tests/ml-powered-queries-repo/notes-api.js +++ /dev/null @@ -1,44 +0,0 @@ -const express = require('express') - -const router = module.exports.router = express.Router(); - -function serializeNote(note) { - return { - title: note.title, - body: note.body - }; -} - -router.post('/find', async (req, res) => { - const notes = await Note.find({ - ownerToken: req.body.token - }).exec(); - res.json({ - notes: notes.map(serializeNote) - }); -}); - -router.get('/findPublic', async (_req, res) => { - const notes = await Note.find({ - isPublic: true - }).exec(); - res.json({ - notes: notes.map(serializeNote) - }); -}); - -router.post('/findVisible', async (req, res) => { - const notes = await Note.find({ - $or: [ - { - isPublic: true - }, - { - ownerToken: req.body.token - } - ] - }).exec(); - res.json({ - notes: notes.map(serializeNote) - }); -}); diff --git a/tests/ml-powered-queries-repo/read-notes.js b/tests/ml-powered-queries-repo/read-notes.js deleted file mode 100644 index 03578874bd..0000000000 --- a/tests/ml-powered-queries-repo/read-notes.js +++ /dev/null @@ -1,37 +0,0 @@ -const mongoose = require('mongoose'); - -Logger = require('./logger').Logger; -Note = require('./models/note').Note; -User = require('./models/user').User; - -(async () => { - if (process.argv.length != 3) { - Logger.log("Outputs all notes visible to a user. Usage: node read-notes.js <token>") - return; - } - - // Open the default mongoose connection - await mongoose.connect('mongodb://localhost:27017/notes', { useFindAndModify: false }); - - const ownerToken = process.argv[2]; - - const user = await User.findOne({ - token: ownerToken - }).exec(); - - const notes = await Note.find({ - $or: [ - { isPublic: true }, - { ownerToken } - ] - }).exec(); - - notes.map(note => { - Logger.log("Title:" + note.title); - Logger.log("By:" + user.name); - Logger.log("Body:" + note.body); - Logger.log(); - }); - - await mongoose.connection.close(); -})(); diff --git a/tests/ml-powered-queries-repo/users-api.js b/tests/ml-powered-queries-repo/users-api.js deleted file mode 100644 index 88381cf7af..0000000000 --- a/tests/ml-powered-queries-repo/users-api.js +++ /dev/null @@ -1,25 +0,0 @@ -const express = require('express') - -Logger = require('./logger').Logger; -const router = module.exports.router = express.Router(); - -router.post('/updateName', async (req, res) => { - Logger.log("/updateName called with new name", req.body.name); - await User.findOneAndUpdate({ - token: req.body.token - }, { - name: req.body.name - }).exec(); - res.json({ - name: req.body.name - }); -}); - -router.post('/getName', async (req, res) => { - const user = await User.findOne({ - token: req.body.token - }).exec(); - res.json({ - name: user.name - }); -});