refactor(standard): fix formating

This commit is contained in:
Christopher Astfalk
2020-10-02 10:55:03 +02:00
parent 70a3a1ac66
commit 90b021db9a
8 changed files with 51 additions and 41 deletions
+2
View File
@@ -126,10 +126,12 @@ function change (app, id, state) {
return 'active'
case 'inactive':
{
const now = Date.now()
sessions.set(id, now)
timeoutIds.add(id)
return 'inactive'
}
default:
throw pouchdbErrors.createError(pouchdbErrors.INVALID_REQUEST, `bad state "${state}"`)
-1
View File
@@ -312,7 +312,6 @@ async function getMacAddress (req, res, next) {
}
} catch (err) {
sendError(res, err)
return
}
} else {
// new and anonym user
+1 -1
View File
@@ -164,7 +164,7 @@ function gridsDidChange (type, grid) {
/**
* Get the users data.
* @param {PouchDB.Database} db The local Database.
* @returns {{ _id: string, _rev: string, accountId: string, name: string }} Doc with user info
* @returns {Promise<{ _id: string, _rev: string, accountId: string, name: string }>} Doc with user info
*/
async function getUserInfo (db) {
const userDoc = await db.get('_local/account')
+21 -20
View File
@@ -1,3 +1,5 @@
'use strict'
const assert = require('assert')
const express = require('express')
const expressPouchDB = require('express-pouchdb')({
@@ -16,16 +18,15 @@ describe('account', function () {
const USERNAME = 'tester.mactestface@example.com'
const PASSWORD = 'bc0e734068f4ef43e22d84e3412c4c0221daa3a001fcd0c7ab24a565f9e7503d'
let testApp
let testServer
let testUsersDb
let usersDb
let server // express server
before('start test server with pouchdb', function (done) {
testApp = express()
testApp.use(expressPouchDB)
global.before('start test server with pouchdb', function (done) {
const app = express()
app.use(expressPouchDB)
testServer = testApp.listen(0, () => {
testServer = app.listen(0, () => {
const port = testServer.address().port
process.env.COUCH_URL = `http://localhost:${port}`
done()
@@ -38,7 +39,7 @@ describe('account', function () {
})
PouchDB.plugin(proxyquire('pouchdb-adapter-memory', {}))
expressPouchDB.setPouchDB(PouchDB)
testUsersDb = new PouchDB('_users')
usersDb = new PouchDB('_users')
})
beforeEach('load server', async function () {
@@ -51,16 +52,16 @@ describe('account', function () {
})
afterEach('destroy the user database', async function () {
await testUsersDb.destroy()
await usersDb.destroy()
})
after('close the server with pouchdb', function () {
global.after('close the server with pouchdb', function () {
testServer.close()
})
// Helper functions
function addUserDoc () {
return testUsersDb.put({
return usersDb.put({
_id: USER_DOC_ID,
type: 'user',
name: USER_ID,
@@ -87,7 +88,7 @@ describe('account', function () {
}
})
const { indexes } = await testUsersDb.getIndexes()
const { indexes } = await usersDb.getIndexes()
assert.deepStrictEqual(indexes[1], {
ddoc: '_design/users-by-email',
def: {
@@ -126,7 +127,7 @@ describe('account', function () {
username: USERNAME
}, 'returns the username')
const userDoc = await testUsersDb.get('org.couchdb.user:' + response.body.data.id)
const userDoc = await usersDb.get('org.couchdb.user:' + response.body.data.id)
assert.strictEqual(userDoc.type, 'user')
assert.deepStrictEqual(userDoc.roles, [])
assert.strictEqual(userDoc.email, USERNAME)
@@ -168,7 +169,7 @@ describe('account', function () {
it('should return a conflict if an account with id exists', async function () {
const id = uuid.v4()
await testUsersDb.put({
await usersDb.put({
_id: 'org.couchdb.user:' + id,
type: 'user',
name: id,
@@ -251,7 +252,7 @@ describe('account', function () {
it('should return a confict if the username already exists', async function () {
const id = uuid.v4()
await testUsersDb.put({
await usersDb.put({
_id: 'org.couchdb.user:' + id,
type: 'user',
name: id,
@@ -365,7 +366,7 @@ describe('account', function () {
describe('PATCH', function () {
it('should update the users document', async function () {
await addUserDoc()
const oldDoc = await testUsersDb.get(USER_DOC_ID)
const oldDoc = await usersDb.get(USER_DOC_ID)
const result = await request(server)
.patch('/api/account')
@@ -381,7 +382,7 @@ describe('account', function () {
})
.expect(204)
const userDoc = await testUsersDb.get(USER_DOC_ID)
const userDoc = await usersDb.get(USER_DOC_ID)
assert.deepStrictEqual(result.body, {}, 'result')
@@ -400,7 +401,7 @@ describe('account', function () {
it('should update the user doc with only a password change', async function () {
await addUserDoc()
const oldDoc = await testUsersDb.get(USER_DOC_ID)
const oldDoc = await usersDb.get(USER_DOC_ID)
await request(server)
.patch('/api/account')
@@ -415,7 +416,7 @@ describe('account', function () {
})
.expect(204)
const userDoc = await testUsersDb.get(USER_DOC_ID)
const userDoc = await usersDb.get(USER_DOC_ID)
assert.notStrictEqual(
userDoc.derived_key,
@@ -455,7 +456,7 @@ describe('account', function () {
const id = 'something'
const nextMail = 'next@example.com'
await testUsersDb.put({
await usersDb.put({
_id: 'org.couchdb.user:' + id,
type: 'user',
name: id,
@@ -606,7 +607,7 @@ describe('account', function () {
await assert.rejects(
async () => {
await testUsersDb.get(USER_DOC_ID)
await usersDb.get(USER_DOC_ID)
},
{
docId: 'org.couchdb.user:3989c4e7-e7ed-48a2-9f2a-a40e520ecd32',
+5 -3
View File
@@ -1,3 +1,5 @@
'use strict'
const assert = require('assert')
const dgram = require('dgram')
const proxyquire = require('proxyquire')
@@ -9,7 +11,7 @@ describe('bridge', function () {
let ws
let server // express server
let app // express app
let app // express app
beforeEach('setup UDP server', function (done) {
testServer = dgram.createSocket('udp4')
@@ -61,7 +63,7 @@ describe('bridge', function () {
it('should require a valid grid session', function (done) {
ws = new WebSocket(getBridgeURL())
let sendData = []
const sendData = []
ws.on('open', () => {
ws.send('oisdfg')
@@ -138,7 +140,7 @@ describe('bridge', function () {
data.readUInt8(0),
data.readUInt8(1),
data.readUInt8(2),
data.readUInt8(3),
data.readUInt8(3)
],
[127, 0, 0, 1],
'IP part was send'
+3 -1
View File
@@ -1,3 +1,5 @@
'use strict'
const assert = require('assert')
const ms = require('milliseconds')
const proxyquire = require('proxyquire')
@@ -7,7 +9,7 @@ const uuid = require('uuid')
describe('gridSession', function () {
let clock
let server // express server
let app // express app
let app // express app
let generateSession
let checkSession
let changeSessionState
+6 -3
View File
@@ -1,3 +1,5 @@
'use strict'
const assert = require('assert')
const express = require('express')
const proxyquire = require('proxyquire')
@@ -9,7 +11,7 @@ describe('httpProxy', function () {
let testServerPort
let server // express server
let app // express app
let app // express app
beforeEach(function (done) {
const testApp = express()
@@ -89,8 +91,9 @@ describe('httpProxy', function () {
const id = uuid.v4()
app.get('gridSessions').set(id, 'active')
let req = request(server)
[method.toLowerCase()](`/api/proxy/http/127.0.0.1:${testServerPort}/`)
const req = request(server)[method.toLowerCase()](
`/api/proxy/http/127.0.0.1:${testServerPort}/`
)
.set('x-andromeda-session-id', id)
// Methods with body
+13 -12
View File
@@ -1,8 +1,9 @@
'use strict'
const assert = require('assert')
const proxyquire = require('proxyquire')
const sinon = require('sinon')
const request = require('supertest')
const uuid = require('uuid')
describe('login', function () {
let clock
@@ -14,11 +15,11 @@ describe('login', function () {
let xmlRpcCreateClient
let fetch
beforeEach(function () {
beforeEach('fake timers', function () {
clock = sinon.useFakeTimers(Date.now())
})
beforeEach(function () {
beforeEach('load server', function () {
usersDbCreateIndex = sinon.stub()
usersDbGet = sinon.stub()
usersDbInsert = sinon.stub()
@@ -574,7 +575,7 @@ describe('login', function () {
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i
)
.expect(function () {
assert.strictEqual(fetch.firstCall.firstArg.href,loginURL)
assert.strictEqual(fetch.firstCall.firstArg.href, loginURL)
})
.expect(200, done)
})
@@ -620,14 +621,14 @@ describe('login', function () {
assert.strictEqual(res.headers['x-andromeda-session-id'], undefined)
})
.expect(500, {
errors: [
{
status: 500,
title: 'Error',
detail: 'test'
}
]
}, done)
errors: [
{
status: 500,
title: 'Error',
detail: 'test'
}
]
}, done)
})
})