Skip to content

Commit

Permalink
chore(ci): make helper integration tests runnable (#6562)
Browse files Browse the repository at this point in the history
* chore(ci): make helper integration tests runnable

* boolean

* hop

* load integration env vars in test jobs

* v4

* v4

* like this?

---------

Co-authored-by: Dhaya <[email protected]>
  • Loading branch information
Haroenv and dhayab authored Feb 17, 2025
1 parent 82990f0 commit a5f9505
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ workflows:
requires:
- build
- unit tests:
context: fx-libraries
requires:
- build
- legacy algoliasearch v3:
requires:
- build
- legacy algoliasearch v4:
context: fx-libraries
requires:
- build
- vue v3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('[INT][FILTERS] Using distinct should let me retrieve all facet without dis
});

helper.on('error', function (event) {
done.fail(event.error);
done(event.error);
});

helper.on('result', function (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('[INT][FILTERS] Should retrieve different values for multi facetted records
var calls = 0;

helper.on('error', function (event) {
done.fail(event.error);
done(event.error);
});

helper.on('result', function (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('[INT][NUMERICS][RAW-API]Test numeric operations on the helper and their re
var calls = 0;

helper.on('error', function (event) {
done.fail(event.error);
done(event.error);
});

helper.on('result', function (event) {
Expand Down Expand Up @@ -85,7 +85,7 @@ test('[INT][NUMERICS][MANAGED-API]Test numeric operations on the helper and thei
var calls = 0;

helper.on('error', function (event) {
done.fail(event.error);
done(event.error);
});

helper.on('result', function (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ test('[INT][SEARCHONCE] Should be able to search once with custom parameters wit

var calls = 1;
helper.on('error', function (event) {
done.fail(event.error);
done(event.error);
});

helper.on('result', function (event) {
if (calls === 3) {
expect(event.results.hits.length).toBe(3);
done();
} else {
done.fail('Should not trigger the result event until the third call');
done(
new Error('Should not trigger the result event until the third call')
);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('[INT][TAGS]Test tags operations on the helper and their results on the alg
var calls = 0;

helper.on('error', function (event) {
done.fail(event.error);
done(event.error);
});

helper.on('result', function (event) {
Expand Down
49 changes: 45 additions & 4 deletions packages/algoliasearch-helper/test/integration-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,50 @@ function setup(indexName, fn) {
// all indexing requests must be done in https
protocol: 'https:',
});
client.deleteIndex =
client.deleteIndex ||
function (deleteIndexName) {
var hasInitIndex = Boolean(client.initIndex);
var originalDeleteIndex = client.deleteIndex
? client.deleteIndex.bind(client)
: undefined;

client.deleteIndex = function (deleteIndexName) {
if (!originalDeleteIndex) {
return client.initIndex(deleteIndexName).delete();
};
}
if (!hasInitIndex) {
return originalDeleteIndex({ indexName: deleteIndexName });
}
return originalDeleteIndex(deleteIndexName);
};
client.listIndexes = client.listIndexes || client.listIndices;
client.initIndex =
client.initIndex ||
function (initIndexName) {
return {
addObjects: function (objects) {
return client.saveObjects({
objects: objects,
indexName: initIndexName,
});
},
clearObjects: function () {
return client.clearObjects({ indexName: initIndexName });
},
setSettings: function (settings) {
return client.setSettings({
indexName: initIndexName,
indexSettings: settings,
});
},
waitTask: function (taskID) {
return client.waitForTask({
indexName,
initIndexName,
taskID: taskID,
});
},
};
};
client.destroy = client.destroy || function () {};

var index = client.initIndex(indexName);
index.addObjects =
Expand All @@ -32,6 +70,9 @@ function setup(indexName, fn) {
};
index.clearIndex = index.clearIndex || index.clearObjects;

// Ensure we go into the right integration branches (and client stays v5)
client.initIndex = hasInitIndex ? client.initIndex : undefined;

return index
.clearIndex()
.then(function (content) {
Expand Down
15 changes: 11 additions & 4 deletions packages/algoliasearch-helper/test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ jest.runCLI(dynamicJestConfig, projectsRootPaths).then(function (response) {
process.env.INTEGRATION_TEST_APPID,
process.env.INTEGRATION_TEST_API_KEY
);
client.deleteIndex =
client.deleteIndex ||
function (deleteIndexName) {
var originalDeleteIndex = client.deleteIndex
? client.deleteIndex.bind(client)
: undefined;
client.deleteIndex = function (deleteIndexName) {
if (!originalDeleteIndex) {
return client.initIndex(deleteIndexName).delete();
};
}
if (!client.initIndex) {
return originalDeleteIndex({ indexName: deleteIndexName });
}
return originalDeleteIndex(deleteIndexName);
};
client.listIndexes = client.listIndexes || client.listIndices;

client.listIndexes().then((content) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('removeExclude should remove an exclusion', function (done) {
try {
helper.removeExclude(facetName, facetValueToExclude);
} catch (e) {
done.fail('Removing unset exclusions should be ok...');
done(new Error('Removing unset exclusions should be ok...'));
}

done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('the response handler should check that the query is not outdated', functio
callCount++;

if (!shouldTriggerResult) {
done.fail('The id was outdated');
done(new Error('The id was outdated'));
}
});

Expand Down Expand Up @@ -78,7 +78,7 @@ test('the error handler should check that the query is not outdated', function (
callCount++;

if (!shouldTriggerError) {
done.fail('The id was outdated');
done(new Error('The id was outdated'));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@ test('Tags filters: switching between advanced and simple API should be forbidde

try {
helper.setQueryParameter('tagFilters', complexQuery);
done.fail("Can't switch directly from the advanced API to the managed API");
done(
new Error(
"Can't switch directly from the advanced API to the managed API"
)
);
} catch (e0) {
helper.clearTags().setQueryParameter('tagFilters', complexQuery);
expect(requestBuilder._getTagFilters(helper.state)).toEqual(complexQuery);
}

try {
helper.addTag('tag').addTag('tag2');
done.fail("Can't switch directly from the managed API to the advanced API");
done(
new Error(
"Can't switch directly from the managed API to the advanced API"
)
);
} catch (e1) {
helper
.setQueryParameter('tagFilters', undefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsear
})
// jest throws an error we need to catch, since stuck in the flow
.catch((e) => {
done.fail(e);
done(e);
})
);
},
Expand Down

0 comments on commit a5f9505

Please sign in to comment.