diff --git a/src/e2e.ts b/src/e2e.ts
index eed7cec9..ad3f79c5 100644
--- a/src/e2e.ts
+++ b/src/e2e.ts
@@ -13,11 +13,10 @@
* this program. If not, see .
*/
-import {SCThings} from '@openstapps/core';
+import {SCThings, SCThingType} from '@openstapps/core';
import {readdir, readFile} from 'fs';
import {join} from 'path';
import {promisify} from 'util';
-import {Bulk} from './bulk';
import {ConnectorClient} from './connectorClient';
import {HttpClientInterface} from './httpClientInterface';
@@ -51,25 +50,23 @@ export async function indexSamples(client: HttpClientInterface, options: E2EOpti
throw new Error('Could not index samples. None were retrived from the file system.');
}
- items.sort((a, b) => (a.type.localeCompare(b.type)));
-
- let currentBulkType;
- let currentBulk: Bulk | undefined;
-
try {
- // Add items depending on their type property with one type per bulk
+ // sort items by type
+ const itemMap: Map = new Map();
for (const item of items) {
- if (currentBulkType !== item.type) {
- if (typeof currentBulk !== 'undefined') {
- await currentBulk.done();
- }
- currentBulk = await api.bulk(item.type, 'stapps-core-sample-data');
- currentBulkType = item.type;
+ if (!itemMap.has(item.type)) {
+ itemMap.set(item.type, []);
}
- await currentBulk!.add(item);
+ const currentItems = itemMap.get(item.type) as SCThings[];
+ currentItems.push(item);
+ itemMap.set(item.type, currentItems);
}
- // close the last open bulk
- if (typeof currentBulk !== 'undefined') {
+ // add items depending on their type property with one type per bulk
+ for (const type of itemMap.keys()) {
+ const currentBulk = await api.bulk(type, 'stapps-core-sample-data');
+ for (const item of (itemMap.get(type) as SCThings[])) {
+ await currentBulk!.add(item);
+ }
await currentBulk.done();
}
} catch (err) {
@@ -92,10 +89,12 @@ export async function getItemsFromSamples(samplesDirectory:
const fileNames = await readDirPromised(samplesDirectory);
for (const fileName of fileNames) {
const filePath = join(samplesDirectory, fileName);
- const fileContent = await readFilePromised(filePath, {encoding: 'utf8'});
- const schemaObject = JSON.parse(fileContent);
- if (schemaObject.errorNames.length === 0 && typeof schemaObject.instance.type === 'string') {
- things.push(schemaObject.instance);
+ if (filePath.endsWith('.json')) {
+ const fileContent = await readFilePromised(filePath, {encoding: 'utf8'});
+ const schemaObject = JSON.parse(fileContent);
+ if (schemaObject.errorNames.length === 0 && typeof schemaObject.instance.type === 'string') {
+ things.push(schemaObject.instance);
+ }
}
}
} catch (error) {