Commit 1e2f988a authored by Oxana's avatar Oxana
Browse files

connect to db try

parent 70c493c6
Pipeline #12284 passed with stages
in 3 minutes and 15 seconds
{
"baseUrl": "http://localhost:4100",
"env": {
"apiUrl": "http://localhost:3000",
"user": {
"email": "tester@test.com",
"password": "password1234",
"username": "testuser"
}
},
"video": false,
"videoCompression": false,
"videoUploadOnPasses": false,
......@@ -16,9 +24,6 @@
"pageLoadTimeout": 120000,
"requestTimeout" : 10000,
"responseTimeout" : 60000,
"env": {
},
"viewportWidth": 1600,
"viewportHeight": 1200,
"retries": {
......
describe('New post', () => {
beforeEach(() => {
cy.task('cleanDatabase')
cy.registerUserIfNeeded()
//cy.login()
})
it('writes a post', () => {})
})
\ No newline at end of file
/**
* @type {Cypress.PluginConfig}
*/
import knexFactory = require('knex')
import { join } from 'path'
module.exports = (on, config) => {
// tasks for resetting database during tests
on('task', {
cleanDatabase () {
const filename = join(__dirname, '..', '..', 'server', '.tmp.db')
const knex = knexFactory({
client: 'sqlite3',
connection: {
filename
},
useNullAsDefault: true
})
// if we are trying to truncate a non-existing table
// that is ok - the server API will create them
const onError = err =>
err.toString().includes('no such table') ? null : Promise.reject(err)
// truncates all tables which removes data left by previous tests
return Promise.all([
knex('Users')
.truncate()
.catch(err =>
err.toString().includes('no such table')
? undefined
: Promise.reject(err)
),
knex('Articles')
.truncate()
.catch(err =>
err.toString().includes('no such table')
? undefined
: Promise.reject(err)
),
knex('ArticleTags')
.truncate()
.catch(err =>
err.toString().includes('no such table')
? undefined
: Promise.reject(err)
),
knex('Comments')
.truncate()
.catch(err =>
err.toString().includes('no such table')
? undefined
: Promise.reject(err)
),
knex('Followers')
.truncate()
.catch(err =>
err.toString().includes('no such table')
? undefined
: Promise.reject(err)
),
knex('ArticleFavorites')
.truncate()
.catch(err =>
err.toString().includes('no such table')
? undefined
: Promise.reject(err)
)
])
},
registerNewUserIfNeeded () {}
})
}
\ No newline at end of file
......@@ -8,5 +8,6 @@ declare namespace Cypress {
* @example cy.dataCy('greeting')
*/
dataCy(value: string): Chainable<Element>
registerUserIfNeeded(options?: {}): void
}
}
\ No newline at end of file
......@@ -16,6 +16,29 @@
// Import commands.js using ES2015 syntax:
import './commands'
const apiUrl = Cypress.env('apiUrl')
Cypress.Commands.add('dataCy', (value) => {
return cy.get(`[data-cy=${value}]`)
})
// creates a user with email and password
// defined in cypress.json environment variables
// if the user already exists, ignores the error
// or given user info parameters
Cypress.Commands.add('registerUserIfNeeded', (options = {}) => {
const defaults = {
image: 'https://robohash.org/6FJ.png?set=set3&size=150x150',
// email, password
...Cypress.env('user')
}
const user = Cypress._.defaults({}, options, defaults)
cy.request({
method: 'POST',
url: `${apiUrl}/api/users`,
body: {
user
},
failOnStatusCode: false
})
})
This diff is collapsed.
......@@ -3,9 +3,11 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"@types/node": "^14.14.20",
"cross-env": "^5.1.4",
"cypress": "^6.2.1",
"cypress-multi-reporters": "^1.4.0",
"knex": "^0.21.15",
"mocha": "^8.2.1",
"mochawesome": "^6.2.1",
"mochawesome-merge": "^4.2.0",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment