-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add : get userinfo function, point system, test (#144)
- Loading branch information
Showing
10 changed files
with
3,394 additions
and
42 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
2 changes: 2 additions & 0 deletions
2
server/prisma/migrations/20220920133736_add_user_point/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "user_point" INTEGER NOT NULL DEFAULT 0; |
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
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,26 @@ | ||
import { Request, Response } from 'express'; | ||
const prisma = require('../db/index'); | ||
|
||
module.exports = { | ||
userInfo: (req: Request, res: Response) => { | ||
const user_id = Number(req.query.user_id as String); | ||
const userInfoHandler = async (user_id: Number) => { | ||
const userInfo = await prisma.User.findMany({ | ||
where: { | ||
user_id: user_id, | ||
}, | ||
}); | ||
return userInfo; | ||
}; | ||
userInfoHandler(user_id) | ||
.then(async (result) => { | ||
await prisma.$disconnect(); | ||
res.status(201).json(result); | ||
}) | ||
.catch(async (e) => { | ||
console.error(e); | ||
await prisma.$disconnect(); | ||
res.status(500).send('Server Error'); | ||
}); | ||
}, | ||
}; |
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,12 +1,12 @@ | ||
import { Router } from "express"; | ||
import { Router } from 'express'; | ||
|
||
const router = Router(); | ||
const { user_login} = require("../controller/login_controller"); | ||
const { user_logout } = require("../controller/logout_controller"); | ||
const { user_login } = require('../controller/login_controller'); | ||
const { user_logout } = require('../controller/logout_controller'); | ||
const { userInfo } = require('../controller/userinfo_controller'); | ||
|
||
router.post("/login", user_login); | ||
router.post("/logout", user_logout); | ||
router.post('/login', user_login); | ||
router.post('/logout', user_logout); | ||
router.get('/userinfo', userInfo); | ||
|
||
module.exports = router; | ||
|
||
|
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,104 @@ | ||
import { expect } from 'chai'; | ||
import { describe } from 'mocha'; | ||
import axios from 'axios'; | ||
|
||
describe('์ปค๋ฎค๋ํฐ ํ๋์ผ๋ก ํฌ์ธํธ ํ๋', () => { | ||
it('๊ธ ์์ฑ์ ํฌ์ธํธ ํ๋', async () => { | ||
const userInfo = await axios.get( | ||
'http://localhost:8000/user/userinfo?user_id=6' | ||
); | ||
const beforePoint: Number = Number(userInfo.data[0].user_point); | ||
|
||
const postArticle = async () => { | ||
await axios.post(`http://localhost:8000/article`, { | ||
user_id: 6, | ||
article_content: 'test article', | ||
}); | ||
const userInfo = await axios.get( | ||
'http://localhost:8000/user/userinfo?user_id=6' | ||
); | ||
const afterPoint = Number(userInfo.data[0].user_point); | ||
return afterPoint; | ||
}; | ||
|
||
const afterPoint = postArticle(); | ||
|
||
expect(Number(afterPoint) - Number(beforePoint)).to.equal(5); | ||
}); | ||
|
||
it('๋๊ธ ์์ฑ์ ํฌ์ธํธ ํ๋', async () => { | ||
const userInfo = await axios.get( | ||
'http://localhost:8000/user/userinfo?user_id=6' | ||
); | ||
const beforePoint: Number = Number(userInfo.data[0].user_point); | ||
|
||
const postComment = async () => { | ||
await axios.post(`http://localhost:8000/comment`, { | ||
user_id: 6, | ||
article_id: 51, | ||
comment_content: 'test comment', | ||
}); | ||
const userInfo = await axios.get( | ||
'http://localhost:8000/user/userinfo?user_id=6' | ||
); | ||
const afterPoint = Number(userInfo.data[0].user_point); | ||
return afterPoint; | ||
}; | ||
|
||
const afterPoint = postComment(); | ||
|
||
expect(Number(afterPoint) - Number(beforePoint)).to.equal(3); | ||
}); | ||
}); | ||
|
||
describe('ํฌ์ธํธ๋ฅผ ํ ํฐ์ผ๋ก ์ ํ', () => { | ||
it('์ ์ฒญํ์ ๋ ํฌ์ธํธ ๋น๊ต', async () => { | ||
const userInfo = await axios.get( | ||
'http://localhost:8000/user/userinfo?user_id=6' | ||
); | ||
const beforePoint: Number = Number(userInfo.data[0].user_point); | ||
|
||
const exchangeToken = async () => { | ||
await axios.post('http://localhost:8000/exchange', { | ||
user_id: 6, | ||
user_point: 5, | ||
}); | ||
const userInfo = await axios.get( | ||
'http://localhost:8000/user/userinfo?user_id=6' | ||
); | ||
const afterPoint = Number(userInfo.data[0].user_point); | ||
return afterPoint; | ||
}; | ||
|
||
const afterPoint = exchangeToken(); | ||
|
||
expect(Number(beforePoint) - Number(afterPoint)).to.equal(5); | ||
}); | ||
it('์ ์ฒญํ์ ๋ ํ ํฐ ๋น๊ต', async () => { | ||
const beforeToken = await axios.post('http://localhost:8000/getbalance', { | ||
address: '0xE8Cf73e4e60c7fbC60A7d5931009aBBAE21B8465', | ||
}); | ||
const numberBeforeToken = Number(beforeToken.data); | ||
|
||
const exchangeToken = async () => { | ||
await axios.post('http://localhost:8000/exchange', { | ||
user_id: 6, | ||
user_point: 5, | ||
}); | ||
const afterToken = await axios.post('http://localhost:8000/getbalance', { | ||
address: '0xE8Cf73e4e60c7fbC60A7d5931009aBBAE21B8465', | ||
}); | ||
const numberAfterToken = Number(afterToken.data); | ||
return numberAfterToken; | ||
}; | ||
|
||
const numberAfterToken = exchangeToken(); | ||
|
||
expect(Number(numberBeforeToken) - Number(numberAfterToken)).to.equal(1); | ||
}); | ||
}); | ||
|
||
describe('nft', () => { | ||
it('ํ ํฐ์ผ๋ก nft ๋ฏผํ ', () => {}); | ||
it('nft๋ก ๋ชจ๋ ๊ฐ์ ์๊ฐ', () => {}); | ||
}); |
Oops, something went wrong.