From ce4206e91ff21822b96a26fa140398ffe7542964 Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 5 Jul 2022 10:52:42 +0200 Subject: [PATCH] Added basic test coverage for the search index module refs https://github.com/TryGhost/Team/issues/1665 - As with all the code we should be aiming for 100% test coverage :) This is a groundwork for testing code that uses HTTP requests - nock was used as it's a library we use in the rest of the projects already --- ghost/sodo-search/src/search-index.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ghost/sodo-search/src/search-index.test.js diff --git a/ghost/sodo-search/src/search-index.test.js b/ghost/sodo-search/src/search-index.test.js new file mode 100644 index 0000000000..d7af0046d1 --- /dev/null +++ b/ghost/sodo-search/src/search-index.test.js @@ -0,0 +1,19 @@ +import {init} from './search-index'; +import nock from 'nock'; + +describe('search index', function () { + test('initializes search index', async () => { + const apiUrl = 'http://localhost/ghost/api/content'; + const apiKey = 'secret_key'; + + const scope = nock('http://localhost/ghost/api/content') + .get('/posts/?key=secret_key&limit=all&fields=id,title,excerpt,url,updated_at,visibility&order=updated_at%20desc&formats=plaintext') + .reply(200, { + posts: [{}] + }); + + await init({apiUrl, apiKey}); + + expect(scope.isDone()).toBeTruthy(); + }); +});