Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
changed the mixin to support both enigma 1 and enigma 2 as well as up…
Browse files Browse the repository at this point in the history
…dated the tests (#33)
  • Loading branch information
Fredrik Folkesson authored and StefanEnberg committed Oct 31, 2017
1 parent b1a714b commit f52ce3c
Show file tree
Hide file tree
Showing 8 changed files with 2,872 additions and 1,223 deletions.
4,004 changes: 2,825 additions & 1,179 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"browser-sync": "^2.18.8",
"coveralls": "^3.0.0",
"cross-env": "^5.1.0",
"enigma.js": "^1.0.0",
"enigma.js": "^2.2.0",
"eslint": "^3.8.0",
"eslint-config-airbnb": "^12.0.0",
"eslint-plugin-import": "^1.16.0",
Expand Down
25 changes: 17 additions & 8 deletions src/enigma-mixin/halyard-enigma-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ function createErrorMessage(errorType, qixError, item) {

const halyardMixin = {
types: 'Global',
init(properties) {
properties.api.Promise = properties.Promise;
init(args) {
if (args.config) {
args.api.Promise = args.config.Promise;
} else {
args.api.Promise = args.Promise;
}
},
extend: {
createSessionAppUsingHalyard(halyard) {
Expand Down Expand Up @@ -74,7 +78,6 @@ const halyardMixin = {
return that.Promise.all(deferredConnections).then(() =>
app.getLocaleInfo().then((localeInfoResult) => {
halyard.setDefaultSetStatements(convertQixGetLocalInfo(localeInfoResult), true);

return app.globalApi.configureReload(true, true, false).then(
() => app.setScript(halyard.getScript()).then(
() => app.doReload().then(() => app.globalApi.getProgress(0).then(
Expand Down Expand Up @@ -106,16 +109,22 @@ const halyardMixin = {
},
};


const exposeGlobalApi = {
types: 'Doc',
init(properties) {
properties.api.globalApi = properties.api.session.getObjectApi({
init(args) {
const getObjectArgs = {
handle: -1,
id: 'Global',
type: 'Global',
customType: 'Global',
delta: true,
});
};
if (args.config) {
getObjectArgs.customType = 'Global';
getObjectArgs.delta = true;
} else {
getObjectArgs.genericType = 'Global';
}
args.api.globalApi = args.api.session.getObjectApi(getObjectArgs);
},
};

Expand Down
26 changes: 13 additions & 13 deletions test/integration/connection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ describe('Connections', () => {
const table = new Halyard.Table(url, { name: 'Allsvenskan', headerRowNr: 1, characterSet: 'utf8' });

halyard.addTable(table);
const docName = Utils.getUniqueDocName();

return Utils.getQixService().then((qix) => {
const docName = Utils.getUniqueDocName();
return Utils.openSession(docName).then((session) => {

return qix.global.createAppUsingHalyard(docName, halyard).then(result => qix.global.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Allsvenskan').then((result) => {
return session.createAppUsingHalyard(docName, halyard).then(result => session.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Allsvenskan').then((result) => {
expect(result[0].qValue[0].qText).to.eql('Lag');
expect(result[1].qValue[0].qText).to.eql('Hammarby');

Expand All @@ -37,18 +37,18 @@ describe('Connections', () => {

halyard.addTable(table);

return Utils.getQixService().then((qix) => {
const docName = Utils.getUniqueDocName();
const docName = Utils.getUniqueDocName();
return Utils.openSession(docName).then((session) => {

return qix.global.createAppUsingHalyard(docName, halyard).then(result => qix.global.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Allsvenskan').then((result) => {
return session.createAppUsingHalyard(docName, halyard).then(result => session.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Allsvenskan').then((result) => {
expect(result[0].qValue[0].qText).to.eql('Lag');
expect(result[1].qValue[0].qText).to.eql('Hammarby');

expect(result[0].qValue[1].qText).to.eql('Hemmasnitt');
expect(result[1].qValue[1].qText).to.eql('11 885');
})))
.catch((err) => {
throw new Error(err.qixError.parameter);
throw err;
});
});
});
Expand All @@ -59,10 +59,10 @@ describe('Connections', () => {

halyard.addTable(JSON.parse(data), 'Car Makers');

return Utils.getQixService().then((qix) => {
const docName = Utils.getUniqueDocName();
const docName = Utils.getUniqueDocName();
return Utils.openSession(docName).then((session) => {

return qix.global.createAppUsingHalyard(docName, halyard).then(result => qix.global.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
return session.createAppUsingHalyard(docName, halyard).then(result => session.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
expect(result[0].qValue[0].qText).to.eql('make_id');
})));
});
Expand All @@ -75,10 +75,10 @@ describe('Connections', () => {

halyard.addTable(table);

return Utils.getQixService().then((qix) => {
const docName = Utils.getUniqueDocName();
const docName = Utils.getUniqueDocName();
return Utils.openSession(docName).then((session) => {

return qix.global.createAppUsingHalyard(docName, halyard).then(result => qix.global.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
return session.createAppUsingHalyard(docName, halyard).then(result => session.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
expect(result[0].qValue[0].qText).to.eql('make_id');
})));
});
Expand Down
4 changes: 2 additions & 2 deletions test/integration/enigma-config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import bluebird from 'bluebird';
import WebSocket from 'ws';
import qixSchema from 'enigma.js/schemas/qix/3.0/schema.json';
import qixSchema from 'enigma.js/schemas/3.2.json';

const config = {
Promise: bluebird,
schema: qixSchema,
session: {
port: '4848',
unsecure: true,
secure: false,
disableCache: true,
},
createSocket(url) {
Expand Down
9 changes: 4 additions & 5 deletions test/integration/enigma-mixin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ halyard.addTable(carmakersPath, 'Car Makers');
describe('Enigma Mixin', () => {
it('should work to reload an existing app', () => {
const docName = Utils.getUniqueDocName();
return Utils.getQixService().then(qix => qix.global.createAppUsingHalyard(docName, halyard).then(appResult => appResult.session.close().then(() => qix.global.reloadAppUsingHalyard(docName, halyard).then(() => qix.global.openApp(docName).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
return Utils.openSession(docName).then(session => session.createAppUsingHalyard(docName, halyard).then(appResult => appResult.session.close().then(() => Utils.openSession(docName)).then((session) => session.reloadAppUsingHalyard(docName, halyard).then(() => session.openDoc(docName).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
expect(result[0].qValue[0].qText).to.eql('make_id');
}))))));
});

it('should work to create a session app with halyard', () => Utils.getQixService().then(qix => qix.global.createSessionAppUsingHalyard(halyard).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
it('should work to create a session app with halyard', () => Utils.openSession().then(session => session.createSessionAppUsingHalyard(halyard).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
expect(result[0].qValue[0].qText).to.eql('make_id');
}))));

it('should work to reload an non-existing app with the createIfMissing param', () => {
const docName = Utils.getUniqueDocName();

return Utils.getQixService().then(qix => qix.global.reloadAppUsingHalyard(docName, halyard, true).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
return Utils.openSession(docName).then(session => session.reloadAppUsingHalyard(docName, halyard, true).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
expect(result[0].qValue[0].qText).to.eql('make_id');
return app.doSave().then(saveresult => app.session.close().then(() => qix.global.reloadAppUsingHalyard(docName, halyard, true).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
return app.doSave().then(saveresult => app.session.close().then(() => Utils.openSession(docName)).then((session) => session.reloadAppUsingHalyard(docName, halyard, true).then(app => app.getTableData(-1, 30, true, 'Car Makers').then((result) => {
expect(result[0].qValue[0].qText).to.eql('make_id');
}))));
})));
Expand Down
6 changes: 3 additions & 3 deletions test/integration/mixin-error-handling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Enigma Mixin error handling', () => {

halyard.addTable(url, { name: 'Table' });

return Utils.getQixService().then(qix => qix.global.createAppUsingHalyard(docName, halyard).then((result) => {})
return Utils.openSession(docName).then(session => session.createAppUsingHalyard(docName, halyard).then((result) => {})
.catch((err) => {
expect(err.type).to.eql('Connection Error');
}));
Expand All @@ -30,7 +30,7 @@ describe('Enigma Mixin error handling', () => {

halyard.addTable(url, { name: 'Allsvenskan', fields: [{ src: 'apa', name: 'Test' }] });

return Utils.getQixService().then(qix => qix.global.createAppUsingHalyard(docName, halyard).then((result) => {})
return Utils.openSession(docName).then(session => session.createAppUsingHalyard(docName, halyard).then((result) => {})
.catch((err) => {
expect(err.type).to.eql('Loading Error');
}));
Expand All @@ -41,7 +41,7 @@ describe('Enigma Mixin error handling', () => {

halyard.addTable(url, { name: 'Allsvenskan', fields: [{ expr: 'adsfasdfdsf(aoa)', name: 'Test' }] });

return Utils.getQixService().then(qix => qix.global.createAppUsingHalyard(docName, halyard).then((result) => {})
return Utils.openSession(docName).then(session => session.createAppUsingHalyard(docName, halyard).then((result) => {})
.catch((err) => {
expect(err.type).to.eql('Syntax Error');
}));
Expand Down
19 changes: 7 additions & 12 deletions test/integration/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,21 @@ enigmaConfig.mixins = enigmaMixin;

const docNamePrefix = 'HalyardIntegrationTest';


export function getUniqueDocName() {
return `${docNamePrefix}-${Math.floor(Math.random() * 100000)}`;
}

export function getQixService() {
return enigma.getService('qix', enigmaConfig);
export function openSession(appId) {
enigmaConfig.url = `ws://localhost:4848/app/engineData-${appId}`;
return enigma.create(enigmaConfig).open();
}

export function removeAllTestDoc() {
return getQixService().then(qix => qix.global.getDocList().then((list) => {
const docsToDelete = [];

return openSession().then(qix => qix.getDocList().then(async (list) => {
const integrationTestDocs = list.filter(doc => doc.qDocName.match(docNamePrefix));

integrationTestDocs.forEach((doc) => {
docsToDelete.push(qix.global.deleteApp(doc.qDocId));
});

return Promise.all(docsToDelete);
for (const doc of integrationTestDocs) {
await qix.deleteApp(doc.qDocId);
}
}));
}

Expand Down

0 comments on commit f52ce3c

Please sign in to comment.