Commit bbf84488 authored by Jure's avatar Jure

test: attempt to test job-xsweet in pipeline

parent 4f9049c4
Pipeline #13065 failed with stages
in 10 minutes and 50 seconds
......@@ -24,6 +24,9 @@ build:
- docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
- echo "Ignore warning! Cannot perform an interactive login from a non TTY device"
- docker push $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
- echo "Building XSweet job runner image"
- docker build -t pubsweet/job-xsweet:$CI_COMMIT_SHA components/server/job-xsweet
- docker push pubsweet/job-xsweet:$CI_COMMIT_SHA
pages:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
......@@ -128,10 +131,31 @@ test:
script:
- cd ${HOME}
# specify host here else it confuses the linked postgres image
- docker build -t pubsweet/job-xsweet components/server/job-xsweet
- docker run -e DATABASE_URL="postgres://test:pw@postgres/test" --name job-xsweet pubsweet/job-xsweet
- PGHOST=postgres yarn test
- docker stop job-xsweet
test:job-xsweet:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
stage: test
variables:
# don't clone repo as image already has it
GIT_STRATEGY: none
# setup data for postgres image
POSTGRES_USER: test
POSTGRES_PASSWORD: pw
# connection details for tests
PGUSER: test
PGPASSWORD: pw
NODE_ENV: test
DATABASE_URL: postgres://test:pw@postgres/test
services:
- postgres
- pubsweet/job-xsweet
except:
- tags
script:
- cd ${HOME}
- PGHOST=postgres cd components/server && yarn jest --testRegex test/standaloneXsweetTest.js
# if tests pass we will push latest, labelled with current commit hash
push:latest:
......
......@@ -4,10 +4,7 @@ Object.assign(global, {
WebSocket,
})
// const { model: User } = require('@pubsweet/model-user')
// const { fixtures } = require('@pubsweet/model-user/test')
// const cleanDB = require('pubsweet-server/test/helpers/db_cleaner')
// const api = require('pubsweet-server/test/helpers/api')
const { destroy } = require('pubsweet-server/src/graphql/pubsub')
const authentication = require('pubsweet-server/src/authentication')
const { startServer } = require('pubsweet-server')
......@@ -18,22 +15,41 @@ const path = require('path')
const { SubscriptionClient } = require('subscriptions-transport-ws')
const superagent = require('superagent')
const wait = require('waait')
jest.setTimeout(60000)
describe('XSweet job', () => {
let token
// let user
let server
beforeEach(async () => {
let client
beforeAll(async () => {
// await cleanDB()
server = await startServer()
// user = await new User(fixtures.user).save()
token = authentication.token.create({ id: 1, username: 'test' })
client = new SubscriptionClient(`ws://localhost:4000/subscriptions`, {
connectionParams: {
authToken: token,
},
})
})
afterAll(async done => {
await destroy()
await server.close()
await wait(500)
done()
})
afterAll(done => server.close(done))
afterEach(async () => {
await client.client.close()
})
it('can process it', async done => {
it('can process it', async () => {
const { body } = await superagent
.post('http://localhost:4000/graphql')
.field(
......@@ -59,18 +75,6 @@ describe('XSweet job', () => {
expect(body.data.createDocxToHTMLJob.status).toBe('Uploading file')
const client = new SubscriptionClient(`ws://localhost:4000/subscriptions`, {
connectionParams: {
authToken: token,
},
})
// client.onConnected(() => {
// // console.log('HELLLO!!!')
// })
// client.onError(e => console.log(e))
const subscriptionPromise = new Promise((resolve, reject) => {
client
.request({
......@@ -88,7 +92,6 @@ describe('XSweet job', () => {
})
.subscribe({
next: async res => {
// console.log(res)
if (res.data.docxToHTMLJob.status === 'Done') {
const { body } = await superagent
.post('http://localhost:4000/graphql')
......@@ -113,10 +116,6 @@ describe('XSweet job', () => {
})
})
await subscriptionPromise
client.unsubscribeAll()
done()
expect(await subscriptionPromise).toBe(true)
})
})
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