Skip to content

Commit

Permalink
fix backend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrkhl committed Apr 30, 2019
1 parent f8431fd commit 3288d02
Show file tree
Hide file tree
Showing 13 changed files with 5,108 additions and 6,694 deletions.
27 changes: 20 additions & 7 deletions backend/.babelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
{
"presets": [
["env", {
"targets": {
"node": "current"
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
}]
]
],
"plugins": [
"transform-decorators-legacy",
"transform-class-properties",
"transform-object-rest-spread"
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
],
"@babel/plugin-proposal-object-rest-spread"
],
"sourceMaps": "both"
}
10 changes: 4 additions & 6 deletions backend/__tests__/integration/library.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import path from 'path';
import { createTestDatabaseConnection } from '../setup';
import { get, post } from '../request';
// import { rmdir } from '../../src/utils/fs';
// import { getConfiguration } from '../../src/get-configuration';
import { createTokenFor } from '../../src/utils/auth';

describe('/library', () => {
Expand All @@ -19,22 +17,22 @@ describe('/library', () => {
await connection.close();
});

describe('/upload', () => {
describe('/upload/zip', () => {
describe('POST', () => {
it('should process ZIP archives containing HTML files', () => {
return post('/library/upload')
return post('/library/upload/zip')
.set('Authorization', 'Bearer ' + authToken)
.attach('file', path.resolve(__dirname, '../dummy-project.zip'))
.expect(200);
});
it('should handle dupes', () => {
return post('/library/upload')
return post('/library/upload/zip')
.set('Authorization', 'Bearer ' + authToken)
.attach('file', path.resolve(__dirname, '../dummy-project.zip'))
.expect(200);
});
it('should return HTTP 400 if no file was attached', () => {
return post('/library/upload')
return post('/library/upload/zip')
.set('Authorization', 'Bearer ' + authToken)
.expect(400);
});
Expand Down
6 changes: 2 additions & 4 deletions backend/__tests__/integration/projects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createTokenFor } from '../../src/utils/auth';
async function createAndGetTestProject(testProjectName, authToken) {
const res = await post('/projects')
.set('Authorization', 'Bearer ' + authToken)
.send({ name: testProjectName })
.send({ projectName: testProjectName })
.expect(200);
return res.body;
}
Expand Down Expand Up @@ -89,9 +89,7 @@ describe('/projects', () => {
.expect(200)
.then(fetchRes => {
expect(fetchRes.body.length).toBeGreaterThan(0);
expect(fetchRes.body.pop().name).toEqual(
'Default Whiteboard'
);
expect(fetchRes.body.pop().name).toEqual('First Whiteboard');
})
));
});
Expand Down
10 changes: 8 additions & 2 deletions backend/__tests__/setup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { View } from '../src/orm/entity/view';
import { Asset } from '../src/orm/entity/asset';
import { InteractionElement } from '../src/orm/entity/interaction-element';
import { Image } from '../src/orm/entity/image';
import { ViewImageInteractionElement } from '../src/orm/entity/view-image-interaction-element';
import { Project } from '../src/orm/entity/project';
import { Whiteboard } from '../src/orm/entity/whiteboard';
import { getConnectionManager } from 'typeorm';
import { Page } from '../src/orm/entity/page';
import { Directory } from '../src/orm/entity/directory';
import { User } from '../src/orm/entity/user';
import { ViewLink } from '../src/orm/entity/view-link';
import { ViewAnnotation } from '../src/orm/entity/view-annotation';

export const createTestDatabaseConnection = () => {
const connectionManager = getConnectionManager();
Expand All @@ -16,12 +19,15 @@ export const createTestDatabaseConnection = () => {
dropSchema: true,
entities: [
Asset,
Image,
Directory,
InteractionElement,
ViewImageInteractionElement,
Page,
Project,
User,
View,
ViewLink,
ViewAnnotation,
Whiteboard
]
});
Expand Down
8 changes: 5 additions & 3 deletions backend/__tests__/unit/auth-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ describe('AuthUtil', () => {
expect(await createHash('haash')).toBeTruthy();
});
});
describe('hashMatches', async () => {
const hash = await createHash('haash');
expect(await hashMatches(hash, 'haash')).toBeTruthy();
describe('hashMatches', () => {
it('should return true for equal strings', async () => {
const hash = await createHash('haash');
expect(await hashMatches(hash, 'haash')).toBeTruthy();
});
});
});
4 changes: 2 additions & 2 deletions backend/__tests__/unit/markup-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFileSync } from 'fs';
import { resolve as resolvePath } from 'path';

describe('MarkupUtil', () => {
describe('extractScriptAssets', async () => {
describe('extractScriptAssets', () => {
it('should return all script assets defined in an HTML document', async () => {
const markup = readFileSync(
resolvePath(__dirname, '../dummy-page.html')
Expand All @@ -13,7 +13,7 @@ describe('MarkupUtil', () => {
expect(scriptAssets.filter(asset => asset.isInline).length).toEqual(1);
});
});
describe('extractStyleAssets', async () => {
describe('extractStyleAssets', () => {
it('should return all style assets defined in an HTML document', async () => {
const markup = readFileSync(
resolvePath(__dirname, '../dummy-page.html')
Expand Down
Loading

0 comments on commit 3288d02

Please sign in to comment.