-
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.
- Loading branch information
Showing
7 changed files
with
4,252 additions
and
1,163 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,30 @@ | ||
import mongoose from "mongoose"; | ||
|
||
export interface IDetails extends Document{ | ||
firstName: string, | ||
lastName: string, | ||
phone: string, | ||
socials: string[] | ||
} | ||
|
||
const detailSchema = new mongoose.Schema({ | ||
firstName: { type: String}, | ||
lastName: {type: String}, | ||
phone: {type: String}, | ||
socials: {type: [String]} | ||
}, | ||
{ | ||
toJSON: { | ||
transform: (doc, ret) => { | ||
return { | ||
firstName: ret.firstName, | ||
lastName: ret.lastName, | ||
phone: ret.phone, | ||
socials: ret.socials | ||
} | ||
} | ||
} | ||
} | ||
); | ||
|
||
export default mongoose.model<IDetails>('Details', detailSchema); |
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,21 @@ | ||
import express, { Request, Response } from "express"; | ||
import Details from "../models/details"; | ||
|
||
const router = express.Router() | ||
|
||
router.get('details', async(res: Response, req: Request) => { | ||
const info = await Details.find() | ||
res.send(info) | ||
}) | ||
|
||
router.post('/details/edit', async(req: Request, res: Response) => { | ||
const {firstName, lastName, phone, socials} = req.params; | ||
const info = new Details ({ | ||
firstName, | ||
lastName, | ||
phone, | ||
socials | ||
}) | ||
|
||
res.json(info) | ||
}) |
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,46 +1,28 @@ | ||
import { expect } from 'chai'; | ||
import chai from 'chai'; | ||
import request from 'supertest'; | ||
import express, { Express } from 'express'; | ||
import bcrypt from 'bcrypt'; | ||
import jwt from 'jsonwebtoken'; | ||
import User from '../models/auth'; | ||
import authRoutes from '../routes/authRoutes'; | ||
|
||
describe('authRoutes', () => { | ||
let app: Express; | ||
|
||
before(() => { | ||
app = express(); | ||
app.use('/', require('../routes/auth').default); | ||
}); | ||
|
||
it('should get user data', async () => { | ||
const res = await request(app).get('/data'); | ||
expect(res.status).to.equal(200); | ||
}); | ||
|
||
it('should create a new user', async () => { | ||
const password = 'password'; | ||
const hashedPassword = await bcrypt.hash(password, 10) | ||
const res = await request(app) | ||
.post('/signup') | ||
.send({ | ||
account: 'admin', | ||
username: 'test', | ||
email: '[email protected]', | ||
password: hashedPassword, | ||
}); | ||
expect(res.status).to.equal(200); | ||
expect(res.body).to.have.property('message', 'User created successfully'); | ||
}); | ||
|
||
it('should login a user', async () => { | ||
const password = 'password'; | ||
const hashedPassword = await bcrypt.hash(password, 10); | ||
const user = new User({ | ||
account: 'admin', | ||
username: 'test', | ||
password: hashedPassword, | ||
describe('Auth Routes', () => { | ||
let app: Express; | ||
before(() => { | ||
app = express(); | ||
app.use('/v1/auth', authRoutes); | ||
}); | ||
it('should get user data', async () => { | ||
const res = await request(app).get('/data'); | ||
}); | ||
it('should create a new user', async () => { | ||
const res = await request(app).post('/signup').send({ | ||
account: 'admin', | ||
username: 'admin', | ||
email: '[email protected]', | ||
password: 'password', | ||
confirmPassword: 'password', | ||
}); | ||
|
||
}); | ||
}); | ||
}); | ||
|
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,36 +0,0 @@ | ||
import { expect } from 'chai'; | ||
import request from 'supertest'; | ||
import mongoose from 'mongoose'; | ||
import express from 'express'; | ||
import bodyParser from 'body-parser'; | ||
import authRoutes from '../routes/authRoutes'; | ||
import blogRoutes from '../routes/blogRoutes'; | ||
import contactRoutes from '../routes/contactRoutes'; | ||
|
||
describe('Server', () => { | ||
let app: express.Express; | ||
|
||
before(() => { | ||
mongoose.connect('mongodb://localhost:27017/test'); | ||
|
||
app = express(); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(bodyParser.json()); | ||
app.use('/v1/auth', authRoutes); | ||
app.use('/v1/blog', blogRoutes); | ||
app.use('/v1/feedback', contactRoutes); | ||
}); | ||
|
||
after(async () => { | ||
await mongoose.connection.close(); | ||
}); | ||
|
||
describe('GET /v1/auth/data', () => { | ||
it('should return user data', async () => { | ||
const res = await request(app).get('/v1/auth/data'); | ||
expect(res.status).to.equal(200); | ||
}); | ||
}); | ||
|
||
|
||
}); | ||
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