diff --git a/Dockerfile b/Dockerfile
index ffc4ea0..2119d9a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -7,4 +7,10 @@ RUN apt-get update
RUN echo yes | apt-get install -y msodbcsql
RUN echo yes | apt-get install -y mssql-tools
RUN locale-gen en_US en_US.UTF-8
-RUN dpkg-reconfigure -f noninteractive locales
\ No newline at end of file
+RUN dpkg-reconfigure -f noninteractive locales
+
+ENV PATH="/opt/mssql-tools/bin:${PATH}"
+ENV ACCEPT_EULA="Y"
+ARG SA_PASSWORD
+
+EXPOSE 1433
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..b258a89
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,14 @@
+version: '3.1'
+services:
+ smartcourse-testing:
+ container_name: 'smartcourse-testing'
+ build:
+ context: .
+ ports:
+ - "1433:1433"
+ environment:
+ SA_PASSWORD: ${LOCAL_SQL_PASSWORD}
+ ACCEPT_EULA: "Y"
+ healthcheck:
+ test: sqlcmd -S localhost,1433 -U SA -P "$SA_PASSWORD" -Q 'select * from smartcourse-testing.testdb.tables'
+
diff --git a/docker.sh b/docker.sh
index 4aa137a..f95937c 100755
--- a/docker.sh
+++ b/docker.sh
@@ -5,20 +5,15 @@ DOCKER_NAME='smartcourse-testing'
docker kill $DOCKER_NAME
docker rm $DOCKER_NAME
+# bail out if any errors
set -ex
-# docker build --tag $DOCKER_NAME .
-docker run \
- --name $DOCKER_NAME \
- --env 'ACCEPT_EULA=Y' \
- --env "SA_PASSWORD=$LOCAL_SQL_PASSWORD" \
- -p 1433:1433 \
- -d microsoft/mssql-server-linux:2017-latest
+# start the container using compose config
+SA_PASSWORD="$LOCAL_SQL_PASSWORD" docker-compose up -d
-sleep 10
-
-docker exec -it $DOCKER_NAME /opt/mssql-tools/bin/sqlcmd \
- -S localhost,1433 -U SA -P "$LOCAL_SQL_PASSWORD" \
+# initdb
+docker exec -it $DOCKER_NAME sqlcmd \
+ -S localhost,1433 \
+ -U SA \
+ -P "$LOCAL_SQL_PASSWORD" \
-Q 'CREATE DATABASE testdb'
-
-# really this should be a dockerfile as with all db config \_(* *)_/
diff --git a/src/controllers/report.js b/src/controllers/report.js
index 8282dea..fe94fba 100644
--- a/src/controllers/report.js
+++ b/src/controllers/report.js
@@ -60,3 +60,13 @@ exports.getReportSummary = function ({ user, query }, res, next) {
.then(getResponseHandler(res))
.catch(next)
}
+
+exports.dismissReport = function ({ user, params }, res, next) {
+ if (user.permissions < PERMISSIONS_MOD) {
+ throw new APIError(ERRORS.MISC.AUTHORIZATION)
+ }
+
+ reportModel.dismissReport(params.id)
+ .then(getResponseHandler(res))
+ .catch(next)
+}
diff --git a/src/models/db/index.js b/src/models/db/index.js
index 2b1ce38..9c5e7d0 100644
--- a/src/models/db/index.js
+++ b/src/models/db/index.js
@@ -13,7 +13,7 @@ class DB extends EventEmitter {
super()
console.log('Connecting to database')
-
+
this.connections = []
this.ready = false
diff --git a/src/models/report.js b/src/models/report.js
index 0e71fdf..26cc164 100644
--- a/src/models/report.js
+++ b/src/models/report.js
@@ -42,6 +42,20 @@ class Report {
.then(([{ id }]) => id)
}
+ /**
+ * Report Id
+ * @param {string} reportId
+ */
+ dismissReport(reportId) {
+ return this.db
+ .run(
+ `DELETE ${REPORTS} WHERE id=@id;`,
+ {
+ [REPORTS]: { id: reportId }
+ }
+ )
+ }
+
/**
* Get all of dem reports for a given post
* @param {object} queryObject
diff --git a/src/routes/index.js b/src/routes/index.js
index 8e44506..fa15de3 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -13,8 +13,8 @@ api.use('/course', courseRouter)
api.use('/subject', subjectRouter)
/* Root API for debugging */
-api.get('/', function (req, res) {
- res.send('
Welcome to the API
')
+api.get('/', function (_, res) {
+ res.sendStatus(200)
})
api.use('*', function (_, res) {
diff --git a/src/routes/uni.js b/src/routes/uni.js
index 35ee078..d95da3a 100644
--- a/src/routes/uni.js
+++ b/src/routes/uni.js
@@ -23,4 +23,7 @@ uni.get('/sessions', uniController.getSessions)
/* Return all posts with reports, sorted by number of reports */
uni.get('/reports', isModOrHigher, reportController.getReportSummary)
+/* Delete the relevant report */
+uni.delete('/report/:id', isModOrHigher, reportController.dismissReport)
+
module.exports = uni
diff --git a/tests/routes/uni.js b/tests/routes/uni.js
index 02220bc..9046cf0 100644
--- a/tests/routes/uni.js
+++ b/tests/routes/uni.js
@@ -9,6 +9,7 @@ describe('Uni route testing', function () {
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
+ .then(_ => _)
)
it('GET uni/faculties', () =>
@@ -17,6 +18,7 @@ describe('Uni route testing', function () {
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
+ .then(_ => _)
)
it('GET uni/sessions', () =>
@@ -43,29 +45,35 @@ describe('Uni route testing', function () {
.set('Authorization', `Bearer ${global.idToken0}`)
.send(report)
.expect(201)
+ .then(body => body)
+
request2 = supertest
.post('/api/course/ACCT1501/question/1/report')
.send(report)
.set('Accept', 'application/json')
.set('Authorization', `Bearer ${global.idToken1}`)
.expect(201)
+ .then(body => body)
+
request3 = supertest
.post('/api/course/ACCT1501/question/2/report')
.send(report)
.set('Accept', 'application/json')
.set('Authorization', `Bearer ${global.idToken1}`)
.expect(201)
+ .then(body => body)
+
// get the reports
- return Promise.all([request1, request2, request3])
- .then(() => {
- getRequest = supertest
- .get('/api/uni/reports')
- .set('Accept', 'application/json')
- .set('Authorization', `Bearer ${global.idTokenSuper}`)
- .expect('Content-Type', /json/)
- .expect(200)
- return getRequest
- })
+ getRequest = Promise.all([request1, request2, request3])
+ .then(() => supertest
+ .get('/api/uni/reports')
+ .set('Accept', 'application/json')
+ .set('Authorization', `Bearer ${global.idTokenSuper}`)
+ .expect('Content-Type', /json/)
+ .expect(200)
+ .then(body => body)
+ )
+ return getRequest
})
it('has 3 entries', () =>
@@ -81,6 +89,37 @@ describe('Uni route testing', function () {
})
)
// NOTE we don't check the number of reports because of the async report test for questions
+
+ describe('DELETE a report', () => {
+ let deleteRequest
+
+ before('delete a report', () => {
+ deleteRequest = getRequest.then(() =>
+ supertest
+ .delete('/api/uni/report/1')
+ .set('Accept', 'application/json')
+ .set('Authorization', `Bearer ${global.idTokenSuper}`)
+ .expect(200)
+ .then(res => res)
+ )
+
+ return deleteRequest
+ })
+
+ it('deletes', () =>
+ deleteRequest.then(
+ () => supertest
+ .get('/api/uni/reports')
+ .set('Accept', 'application/json')
+ .set('Authorization', `Bearer ${global.idTokenSuper}`)
+ .expect('Content-Type', /json/)
+ .expect(200)
+ .then(({ body }) => {
+ expect(body.length).to.equal(2)
+ })
+ )
+ )
+ })
})
describe('GET uni/reports (error)', () => {
@@ -93,6 +132,8 @@ describe('Uni route testing', function () {
.set('Authorization', `Bearer ${global.idToken0}`)
.expect('Content-Type', /json/)
.expect(403)
+ .then(data => data)
+
return getRequest
})
@@ -112,6 +153,8 @@ describe('Uni route testing', function () {
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
+ .then(data => data)
+
return getRequest
})