Skip to content

Remove api key from mandatory config #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 23, 2021
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ If you already have your own scraper but you still want to use MeiliSearch and `
</html>
```

The `hostUrl` and the `apiKey` fields are the credentials of your MeiliSearch instance.<br>
The `hostUrl` and the `apiKey` (_optional_) fields are the credentials of your MeiliSearch instance.<br>
`indexUid` is the index identifier in your MeiliSearch instance in which your website content is stored.<br>
`inputSelector` is the `id` attribute of the HTML search input tag.

Expand Down
3 changes: 1 addition & 2 deletions src/lib/DocsSearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class DocsSearchBar {
* @returns {void}
*/
static checkArguments(args) {
if (!args.apiKey || !args.indexUid || !args.hostUrl) {
if (!args.inputSelector || !args.indexUid || !args.hostUrl) {
throw new Error(usage)
}

Expand Down Expand Up @@ -302,7 +302,6 @@ class DocsSearchBar {
groupedHits[level] = flattenedHits
})
groupedHits = utils.flattenAndFlagFirst(groupedHits, 'isCategoryHeader')

// Translate hits into smaller objects to be send to the template
return groupedHits.map((hit) => {
const url = DocsSearchBar.formatURL(hit)
Expand Down
6 changes: 4 additions & 2 deletions src/lib/__tests__/DocsSearchBar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@ describe('DocsSearchBar', () => {
const options = {
apiKey: 'apiKey',
indexUid: 'indexUID',
inputSelector: '#',
}

// When
expect(() => {
checkArguments(options)
}).toThrow(/^Usage:/)
})
it('should throw an error if no apiKey defined', () => {
it('should throw an error if no inputSelector defined', () => {
// Given
const options = {
hostUrl: 'test.com',
Expand All @@ -268,7 +269,7 @@ describe('DocsSearchBar', () => {
// Given
const options = {
hostUrl: 'test.com',
apiKey: 'apiKey',
inputSelector: '#',
}

// When
Expand All @@ -282,6 +283,7 @@ describe('DocsSearchBar', () => {
hostUrl: 'test.com',
apiKey: 'apiKey',
indexUid: 'indexUID',
inputSelector: '#',
}
sinon.stub(DocsSearchBar, 'getInputFromSelector').returns(false)

Expand Down