-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3c6272
commit 0f2050b
Showing
16 changed files
with
524 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
[ | ||
{ | ||
"testName": "client throws with invalid parameters", | ||
"autoCreateClient": false, | ||
"steps": [ | ||
{ | ||
"type": "createClient", | ||
"parameters": { | ||
"apiKey": "blah" | ||
}, | ||
"expected": { | ||
"error": "appId is missing!" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"testName": "client has instance variables for appId and apiKey", | ||
"autoCreateClient": false, | ||
"steps": [ | ||
{ | ||
"type": "createClient", | ||
"parameters": { | ||
"appId": "my-app-id", | ||
"apiKey": "my-api-key" | ||
} | ||
}, | ||
{ | ||
"type": "variable", | ||
"object": "$client", | ||
"path": ["appId"], | ||
"expected": { "match": "my-app-id" } | ||
}, | ||
{ | ||
"type": "variable", | ||
"object": "$client", | ||
"path": ["apiKey"], | ||
"expected": { "match": "my-api-key" } | ||
} | ||
] | ||
}, | ||
{ | ||
"testName": "sets user agent", | ||
"steps": [ | ||
{ | ||
"type": "method", | ||
"object": "$client", | ||
"path": ["setUserAgent"], | ||
"parameters": ["hello"] | ||
}, | ||
{ | ||
"type": "method", | ||
"object": "$client", | ||
"path": ["getUserAgent"], | ||
"expected": { "match": "hello" } | ||
} | ||
] | ||
}, | ||
{ | ||
"testName": "save objects and perform a basic search", | ||
"autoCreateIndex": true, | ||
"steps": [ | ||
{ | ||
"type": "method", | ||
"object": "$index", | ||
"path": ["saveObjects"], | ||
"parameters": [ | ||
[ | ||
{ | ||
"objectID": "julien-lemoine", | ||
"company": "Algolia", | ||
"name": "Julien Lemoine" | ||
}, | ||
{ | ||
"objectID": "nicolas-dessaigne", | ||
"company": "Algolia", | ||
"name": "Nicolas Dessaigne" | ||
}, | ||
{ "company": "Amazon", "name": "Jeff Bezos" }, | ||
{ "company": "Apple", "name": "Steve Jobs" }, | ||
{ "company": "Apple", "name": "Steve Wozniak" }, | ||
{ "company": "Arista Networks", "name": "Jayshree Ullal" }, | ||
{ "company": "Google", "name": "Larry Page" }, | ||
{ "company": "Google", "name": "Rob Pike" }, | ||
{ "company": "Google", "name": "Serguey Brin" }, | ||
{ "company": "Microsoft", "name": "Bill Gates" }, | ||
{ "company": "SpaceX", "name": "Elon Musk" }, | ||
{ "company": "Tesla", "name": "Elon Musk" }, | ||
{ "company": "Yahoo", "name": "Marissa Mayer" } | ||
], | ||
{ | ||
"autoGenerateObjectIDIfNotExist": true | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "method", | ||
"object": "$index", | ||
"path": ["setSettings"], | ||
"parameters": [{ "attributesForFaceting": ["searchable(company)"] }] | ||
}, | ||
{ | ||
"type": "method", | ||
"object": "$index", | ||
"path": ["search"], | ||
"parameters": ["algolia"], | ||
"expected": { | ||
"match": [ | ||
{ | ||
"objectContaining": { | ||
"name": "Julien Lemoine" | ||
} | ||
}, | ||
{ | ||
"objectContaining": { | ||
"name": "Nicolas Dessaigne" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "method", | ||
"object": "$index", | ||
"path": ["search"], | ||
"parameters": [ | ||
"elon", | ||
{ | ||
"facets": ["*"], | ||
"facetFilters": [["company:tesla", "company:spacex"]] | ||
} | ||
], | ||
"expected": { | ||
"length": 2, | ||
"match": [ | ||
{ "objectContaining": { "company": "SpaceX" } }, | ||
{ "objectContaining": { "company": "Tesla" } } | ||
] | ||
} | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
new {{client}}('{{parameters.appId}}', '{{parameters.apiKey}}'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{#error}} | ||
{{/error}} | ||
{{#length}} | ||
expect(result).toHaveLength({{length}}); | ||
{{/length}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
await {{object}}{{#path}}.{{.}}{{/path}}({{{parameters}}}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{#isCreateClient}} | ||
const $client = {{> createClient}} | ||
result = $client; | ||
{{/isCreateClient}} | ||
|
||
{{#isVariable}} | ||
result = {{> variable}} | ||
{{/isVariable}} | ||
|
||
{{#isMethod}} | ||
result = {{> method}} | ||
{{/isMethod}} | ||
|
||
{{#expected}} | ||
{{> expected}} | ||
{{/expected}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { {{client}} } from '{{{import}}}'; | ||
|
||
const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; | ||
const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; | ||
|
||
function createClient() { | ||
return new {{client}}(appId, apiKey{{#hasRegionalHost}}, 'us'{{/hasRegionalHost}}); | ||
} | ||
|
||
async function createIndex() { | ||
// TODO | ||
} | ||
|
||
{{#blocks}} | ||
describe('{{operationId}}', () => { | ||
{{#tests}} | ||
test('{{testName}}', async () => { | ||
{{#autoCreateClient}} | ||
const $client = createClient(); | ||
{{/autoCreateClient}} | ||
{{#autoCreateIndex}} | ||
const $index = await createIndex(); | ||
{{/autoCreateIndex}} | ||
|
||
let result; | ||
{{#steps}} | ||
{{#expectedError}} | ||
expect(() => { | ||
{{> step}} | ||
}).toThrowError("{{expectedError}}") | ||
{{/expectedError}} | ||
|
||
{{^expectedError}} | ||
{{> step}} | ||
{{/expectedError}} | ||
{{/steps}} | ||
}); | ||
|
||
{{/tests}} | ||
}) | ||
|
||
{{/blocks}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{object}}{{#path}}.{{.}}{{/path}}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { SearchApi } from '@algolia/client-search'; | ||
|
||
const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; | ||
const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; | ||
|
||
function createClient() { | ||
return new SearchApi(appId, apiKey); | ||
} | ||
|
||
async function createIndex() { | ||
// TODO | ||
} | ||
|
||
describe('basic', () => { | ||
test('client throws with invalid parameters', async () => { | ||
let result; | ||
expect(() => { | ||
const $client = new SearchApi('', 'blah'); | ||
result = $client; | ||
}).toThrowError('appId is missing!'); | ||
}); | ||
|
||
test('client has instance variables for appId and apiKey', async () => { | ||
let result; | ||
|
||
const $client = new SearchApi('my-app-id', 'my-api-key'); | ||
result = $client; | ||
|
||
result = $client.appId; | ||
|
||
result = $client.apiKey; | ||
}); | ||
|
||
test('sets user agent', async () => { | ||
const $client = createClient(); | ||
|
||
let result; | ||
|
||
result = await $client.setUserAgent('hello'); | ||
|
||
result = await $client.getUserAgent(); | ||
}); | ||
|
||
test('save objects and perform a basic search', async () => { | ||
const $client = createClient(); | ||
const $index = await createIndex(); | ||
|
||
let result; | ||
|
||
result = await $index.saveObjects( | ||
[ | ||
{ | ||
objectID: 'julien-lemoine', | ||
company: 'Algolia', | ||
name: 'Julien Lemoine', | ||
}, | ||
{ | ||
objectID: 'nicolas-dessaigne', | ||
company: 'Algolia', | ||
name: 'Nicolas Dessaigne', | ||
}, | ||
{ company: 'Amazon', name: 'Jeff Bezos' }, | ||
{ company: 'Apple', name: 'Steve Jobs' }, | ||
{ company: 'Apple', name: 'Steve Wozniak' }, | ||
{ company: 'Arista Networks', name: 'Jayshree Ullal' }, | ||
{ company: 'Google', name: 'Larry Page' }, | ||
{ company: 'Google', name: 'Rob Pike' }, | ||
{ company: 'Google', name: 'Serguey Brin' }, | ||
{ company: 'Microsoft', name: 'Bill Gates' }, | ||
{ company: 'SpaceX', name: 'Elon Musk' }, | ||
{ company: 'Tesla', name: 'Elon Musk' }, | ||
{ company: 'Yahoo', name: 'Marissa Mayer' }, | ||
], | ||
{ autoGenerateObjectIDIfNotExist: true } | ||
); | ||
|
||
result = await $index.setSettings({ | ||
attributesForFaceting: ['searchable(company)'], | ||
}); | ||
|
||
result = await $index.search('algolia'); | ||
|
||
result = await $index.search('elon', { | ||
facets: ['*'], | ||
facetFilters: [['company:tesla', 'company:spacex']], | ||
}); | ||
|
||
expect(result).toHaveLength(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.