Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ lerna-debug.log
!**/.env.schema
**/package-lock.json

*.tsbuildinfo
*.tsbuildinfo
# TODO: Remove after testing
/modules/server/testConfigs*
103 changes: 53 additions & 50 deletions integration-tests/admin/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { after, before, describe } from 'node:test';

Copy link
Contributor Author

@demariadaniel demariadaniel Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up that multiple files include simple prettier cleanup changes to clear up the repo (mostly order of imports, whitespace, & falsy handling) or Typescript updates to declutter the repo.

The main change is the creation of a SearchClient which replaces instances of ElasticSearch Client.

import { Client } from '@elastic/elasticsearch';
import express from 'express';

import Arranger, { adminGraphql } from '../../../modules/server/dist';
import ajax from '../../../modules/server/dist/utils/ajax';
import addProject from './addProject';
import Arranger, { adminGraphql } from '../../../modules/server/dist/index.js';
import ajax from '../../../modules/server/dist/utils/ajax.js';

import addProject from './addProject.js';

const file_centric_mapppings = require('./assets/file_centric.mappings.json');

Expand All @@ -19,58 +22,58 @@ const app = express();

const api = ajax(`http://localhost:${port}`);
const esClient = new Client({
...(useAuth && {
auth: {
username: esUser,
password: esPwd,
},
}),
node: esHost,
...(useAuth && {
auth: {
username: esUser,
password: esPwd,
},
}),
node: esHost,
});

const cleanup = () =>
Promise.all([
esClient.indices.delete({
index: esIndex,
}),
esClient.indices.delete({
index: 'arranger-projects*',
}),
]);
Promise.all([
esClient.indices.delete({
index: esIndex,
}),
esClient.indices.delete({
index: 'arranger-projects*',
}),
]);

describe('@arranger/admin', () => {
let server;
const adminPath = '/admin/graphql';
before(async () => {
console.log('===== Initializing Elasticsearch data =====');
try {
await cleanup();
} catch (err) {}
await esClient.indices.create({
index: esIndex,
body: file_centric_mapppings,
});
let server;
const adminPath = '/admin/graphql';
before(async () => {
console.log('===== Initializing Elasticsearch data =====');
try {
await cleanup();
} catch (err) {}
await esClient.indices.create({
index: esIndex,
body: file_centric_mapppings,
});

console.log('===== Starting arranger app for test =====');
const router = await Arranger({ esHost, enableAdmin: false });
const adminApp = await adminGraphql({ esHost });
adminApp.applyMiddleware({ app, path: adminPath });
app.use(router);
await new Promise((resolve) => {
server = app.listen(port, () => {
resolve();
});
});
});
after(async () => {
server?.close();
await cleanup();
});
console.log('===== Starting arranger app for test =====');
const router = await Arranger({ esHost, enableAdmin: false });
const adminApp = await adminGraphql({ esHost });
adminApp.applyMiddleware({ app, path: adminPath });
app.use(router);
await new Promise((resolve) => {
server = app.listen(port, () => {
resolve();
});
});
});
after(async () => {
server?.close();
await cleanup();
});

const env = {
api,
esIndex,
adminPath,
};
addProject(env);
const env = {
api,
esIndex,
adminPath,
};
addProject(env);
});
157 changes: 58 additions & 99 deletions integration-tests/server/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { after, before, suite } from 'node:test';

import { Client } from '@elastic/elasticsearch';
import Arranger from '@overture-stack/arranger-server';
import ajax from '@overture-stack/arranger-server/dist/utils/ajax.js';
import express from 'express';

// import { print } from 'graphql';
// import gql from 'graphql-tag';
// import Arranger, { adminGraphql } from '../../../modules/server/dist';
import getSearchClient from '../../../modules/server/src/searchClient/index.js';

// test modules
import data from './assets/model_centric.data.json';
Expand All @@ -26,6 +23,7 @@ const setsIndex = process.env.ES_ARRANGER_SET_INDEX || 'arranger-sets-testing';
const esPwd = process.env.ES_PASS;
const esUser = process.env.ES_USER;
const port = process.env.PORT || 5678;
const clientType = process.env.SEARCH_CLIENT;

const useAuth = !!esPwd && !!esUser;

Expand All @@ -36,14 +34,15 @@ const api = ajax(`http://localhost:${port}`, {
endpoint: '/graphql',
});

const esClient = new Client({
const esClient = await getSearchClient({
...(useAuth && {
auth: {
username: esUser,
password: esPwd,
},
}),
node: esHost,
clientType,
});

const cleanup = () => {
Expand All @@ -61,110 +60,70 @@ suite('integration-tests/server', () => {
let server;
const documentType = 'model';

before(async () => {
console.log('\n(Initializing Elasticsearch and Arranger)');
before(
async () => {
console.log('\n(Initializing Elasticsearch and Arranger)');

try {
await cleanup();
} catch (err) {
//
}
try {
await cleanup();
} catch (err) {
//
}

await esClient.indices.create({
index: esIndex,
body: mappings,
});

for (const datum of data) {
await esClient.index({
await esClient.indices.create({
index: esIndex,
id: datum._id,
body: datum._source,
refresh: 'wait_for',
body: mappings,
});
}

try {
const router = await Arranger({
// needed to see the mapping
enableAdmin,
// This may be useful when troubleshooting tests
enableLogs: true,
esHost,
getServerSideFilter: () => ({
op: 'not',
content: [
{
op: 'in',
content: {
fieldName: 'access_denied',
value: ['true'],
for (const datum of data) {
await esClient.index({
index: esIndex,
id: datum._id,
body: datum._source,
refresh: 'wait_for',
});
}

try {
const router = await Arranger({
// needed to see the mapping
enableAdmin,
// This may be useful when troubleshooting tests
enableLogs: true,
esHost,
getServerSideFilter: () => ({
op: 'not',
content: [
{
op: 'in',
content: {
fieldName: 'access_denied',
value: ['true'],
},
},
},
],
}),
setsIndex,
});

app.use(router);
],
}),
setsIndex,
});

// TODO: reenable once Admin is back online
// const adminApp = await adminGraphql({ esHost });
// adminApp.applyMiddleware({ app, path: adminPath });
app.use(router);

await new Promise((resolve) => {
server = app.listen(port, () => {
resolve(null);
await new Promise((resolve) => {
server = app.listen(port, () => {
resolve(null);
});
});
});

// TODO: reenable once Admin is back online
// /**
// * uses the admin API to adds some metadata
// */
// await api.post({
// endpoint: adminPath,
// body: {
// query: print(gql`
// mutation($projectId: String!) {
// newProject(id: $projectId) {
// id
// __typename
// }
// }
// `),
// variables: {
// projectId,
// },
// },
// });

// await api.post({
// endpoint: adminPath,
// body: {
// query: print(gql`
// mutation($projectId: String!, $documentType: String!, $esIndex: String!) {
// newIndex(projectId: $projectId, documentType: $documentType, esIndex: $esIndex) {
// id
// }
// }
// `),
// variables: {
// projectId,
// documentType,
// esIndex,
// },
// },
// });

console.log('******* Starting tests *******');
} catch (err) {
console.error('error:', err);
throw err;
}
}, {
timeout: 10000,
});
console.log('******* Starting tests *******');
} catch (err) {
console.error('error:', err);
throw err;
}
},
{
timeout: 10000,
},
);

after(async () => {
try {
Expand Down
9 changes: 3 additions & 6 deletions integration-tests/server/test/manageSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default ({ api, documentType }) => {

assert.equal(data.errors, undefined);

setId = data.data.newSet.setId;
setId = data?.data?.newSet?.setId;
});

test('2.retrieves newly created set successfully', async () => {
Expand Down Expand Up @@ -55,11 +55,8 @@ export default ({ api, documentType }) => {
});

assert.equal(data.errors, undefined);
const allSetIds = data.data.sets.hits.edges.map(({ node }) => node.setId);
const allSetIds = data?.data?.sets?.hits?.edges.map(({ node }) => node.setId) || [];

assert.ok(
allSetIds.includes(setId),
`Expected [${allSetIds.join(', ')}] to include ${setId}`
);
assert.ok(allSetIds.includes(setId), `Expected [${allSetIds.join(', ')}] to include ${setId}`);
});
};
Loading