Skip to content

Commit

Permalink
Cleanup - remove database and unused exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkvon committed Jan 17, 2024
1 parent 97fdfc8 commit 4dd4fa0
Show file tree
Hide file tree
Showing 10 changed files with 1,926 additions and 528 deletions.
9 changes: 0 additions & 9 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ SMTP_TRANSPORT_REQUIRE_TLS=
# email address which will be the sender of the notifications and email verification messages
EMAIL_SENDER=[email protected]

# Database configuration
DB_DIALECT=sqlite
DB_STORAGE=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
DB_HOST=
DB_PORT=

# JWT
# path to JWT (private) key
# you can use the command `openssl ecparam -name prime256v1 -genkey -noout -out ecdsa-p256-private.pem` to generate one
Expand Down
14 changes: 14 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
- plugin:prettier/recommended
- plugin:import/recommended
- plugin:import/typescript
settings:
import/parsers:
'@typescript-eslint/parser':
- .ts
import/resolver:
typescript:
alwaysTryTypes: true
node: true

parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: 9
Expand All @@ -17,3 +28,6 @@ rules:
- args: after-used
ignoreRestSiblings: false
'no-console': 'warn'
import/no-unused-modules:
- warn
- unusedExports: true
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@
"@types/sinon": "^10.0.15",
"@types/tough-cookie": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@typescript-eslint/parser": "^6.19.0",
"chai": "^4.3.7",
"cheerio": "^1.0.0-rc.12",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.0.0",
"install": "^0.13.0",
"maildev": "^2.1.0",
"mocha": "^10.2.0",
"msw": "^2.0.14",
"npm": "^10.3.0",
"prettier": "^3.0.0",
"rdf-namespaces": "^1.11.0",
"sinon": "^15.2.0",
Expand Down Expand Up @@ -69,8 +73,6 @@
"lodash": "^4.17.21",
"n3": "^1.17.0",
"nodemailer": "^6.9.4",
"parse-link-header": "^2.0.0",
"sequelize": "^6.32.1",
"sqlite3": "^5.1.6"
"parse-link-header": "^2.0.0"
}
}
12 changes: 0 additions & 12 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dotenv/config'
import SMTPTransport from 'nodemailer/lib/smtp-transport'
import { Dialect, Options } from 'sequelize'

// the defaults work for tests. you should define your own
// either via .env file, or via environment variables directly (depends on your setup)
Expand Down Expand Up @@ -47,17 +46,6 @@ export const port: number = +(process.env.PORT ?? 3005)
// email verification expiration in seconds (1 hour)
export const emailVerificationExpiration = 3600

// configuration of database in form of sequelize options
export const database: Options = {
dialect: (process.env.DB_DIALECT as Dialect) ?? 'sqlite',
storage: process.env.DB_STORAGE || undefined, // Path to the SQLite database file (default is memory)
database: process.env.DB_DATABASE || undefined,
username: process.env.DB_USERNAME || undefined,
password: process.env.DB_PASSWORD || undefined,
host: process.env.DB_HOST || undefined,
port: process.env.DB_PORT ? +process.env.DB_PORT : undefined,
}

export const isBehindProxy = stringToBoolean(process.env.BEHIND_PROXY)

const stringToArray = (value: string | undefined) => {
Expand Down
56 changes: 0 additions & 56 deletions src/config/sequelize.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/controllers/integration.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { readFile } from 'fs-extra'
import jsonwebtoken, {
JsonWebTokenError,
TokenExpiredError,
} from 'jsonwebtoken'
import * as jsonwebtoken from 'jsonwebtoken'
import { JsonWebTokenError, TokenExpiredError } from 'jsonwebtoken'
import { Middleware } from 'koa'
import { pick } from 'lodash'
import * as config from '../config'
Expand Down
10 changes: 5 additions & 5 deletions src/test/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai'
import * as cheerio from 'cheerio'
import { createAccount } from 'css-authn/dist/7.x'
import { createSandbox } from 'sinon'
import * as uuid from 'uuid'
import { v4 as uuidv4 } from 'uuid'
import * as config from '../../config'
import * as mailerService from '../../services/mailerService'

Expand All @@ -12,9 +12,9 @@ export const createRandomAccount = ({
solidServer: string
}) => {
return createAccount({
username: uuid.v4(),
password: uuid.v4(),
email: uuid.v4() + '@example.com',
username: uuidv4(),
password: uuidv4(),
email: uuidv4() + '@example.com',
provider: solidServer,
})
}
Expand Down Expand Up @@ -45,7 +45,7 @@ export const initIntegration = async ({
return { verificationLink }
}

export const finishIntegration = async (verificationLink: string) => {
const finishIntegration = async (verificationLink: string) => {
const response = await fetch(verificationLink)
expect(response.ok).to.be.true
const jwt = await response.text()
Expand Down
62 changes: 3 additions & 59 deletions src/test/helpers/setupPod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai'
import { foaf, ldp, solid, space } from 'rdf-namespaces'
import { foaf, solid, space } from 'rdf-namespaces'
import * as config from '../../config'
import { Person } from './types'

Expand Down Expand Up @@ -124,68 +124,12 @@ export const setupEmailSettings = async ({
})
}

export const setupInbox = async ({
webId,
inbox,
authenticatedFetch,
}: {
webId: string
inbox: string
authenticatedFetch: typeof fetch
}) => {
// create inbox
const createInboxResponse = await authenticatedFetch(inbox, {
method: 'PUT',
headers: {
link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"',
'content-type': 'text/turtle',
},
})

expect(createInboxResponse.ok).to.be.true

const createInboxAclResponse = await authenticatedFetch(inbox + '.acl', {
// this .acl is a shortcut, should find .acl properly TODO
method: 'PUT',
headers: { 'content-type': 'text/turtle' },
body: `
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
<#Append>
a acl:Authorization;
acl:agentClass acl:AuthenticatedAgent;
acl:accessTo <./>;
acl:default <./>;
acl:mode acl:Append.
<#ControlReadWrite>
a acl:Authorization;
acl:agent <${webId}>;
acl:accessTo <./>;
acl:default <./>;
acl:mode acl:Control, acl:Read, acl:Write.
`,
})

expect(createInboxAclResponse.ok).to.be.true

const linkInboxResponse = await authenticatedFetch(webId, {
method: 'PATCH',
headers: { 'content-type': 'text/n3' },
body: `
_:mutate a <${solid.InsertDeletePatch}>; <${solid.inserts}> {
<${webId}> <${ldp.inbox}> <${inbox}>.
}.`,
})

expect(linkInboxResponse.ok).to.be.true
}

/**
* Give agent a read access (e.g. to inbox)
*
* Currently assumes we're changing rights to container!
*/
export const addRead = async ({
const addRead = async ({
resource,
agent,
authenticatedFetch,
Expand Down Expand Up @@ -215,7 +159,7 @@ export const addRead = async ({
return response
}

export const addPublicRead = async ({
const addPublicRead = async ({
resource,
authenticatedFetch,
}: {
Expand Down
9 changes: 0 additions & 9 deletions src/test/testSetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { HttpResponse, http } from 'msw'
import { SetupServer, setupServer } from 'msw/node'
import app from '../app'
import { port } from '../config'
import { EmailVerification, Integration } from '../config/sequelize'
import { createRandomAccount } from './helpers'
import type { Person } from './helpers/types'

Expand Down Expand Up @@ -74,12 +73,6 @@ after(done => {
maildev.close(done)
})

// clear the database before each test
beforeEach(async () => {
await EmailVerification.destroy({ truncate: true })
await Integration.destroy({ truncate: true })
})

/**
* Before each test, create a new account and authenticate to it
*/
Expand Down Expand Up @@ -133,10 +126,8 @@ afterEach(() => {
export {
authenticatedFetch,
authenticatedFetch3,
cssServer,
otherAuthenticatedFetch,
otherPerson,
person,
person3,
server,
}
Loading

0 comments on commit 4dd4fa0

Please sign in to comment.