-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from Clarifai/release-9-1
Release 9/1/2017
- Loading branch information
Showing
29 changed files
with
1,848 additions
and
77 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ out/* | |
docs | ||
node_modules/* | ||
examples/node_modules | ||
.babelrc |
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
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
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
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
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
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,63 @@ | ||
const Clarifai = require('./../src'); | ||
const {errorHandler} = require('./helpers'); | ||
const {sampleImages} = require('./test-data'); | ||
|
||
describe('API key', () => { | ||
it('can initialize an app with an api key', done => { | ||
const anApp = new Clarifai.App({apiKey: process.env.API_KEY}); | ||
expect(anApp._config.apiKey).toEqual(process.env.API_KEY); | ||
done(); | ||
}); | ||
|
||
it('can make calls with an api key', done => { | ||
const anApp = new Clarifai.App({apiKey: process.env.API_KEY}); | ||
anApp.models.predict(Clarifai.GENERAL_MODEL, [ | ||
{ | ||
'url': sampleImages[0] | ||
}, | ||
{ | ||
'url': sampleImages[1] | ||
} | ||
]) | ||
.then(response => { | ||
expect(response.outputs).toBeDefined(); | ||
const outputs = response.outputs; | ||
expect(outputs.length).toBe(2); | ||
const output = outputs[0]; | ||
expect(output.id).toBeDefined(); | ||
expect(output.status).toBeDefined(); | ||
expect(output.input).toBeDefined(); | ||
expect(output.model).toBeDefined(); | ||
expect(output.created_at).toBeDefined(); | ||
expect(output.data).toBeDefined(); | ||
done(); | ||
}) | ||
.catch(errorHandler.bind(done)); | ||
}); | ||
|
||
it('Sets a token with an object', done => { | ||
const token = { | ||
access_token: 'foo', | ||
token_type: 'Bearer', | ||
expires_in: 100000, | ||
scope: 'api_access_write api_access api_access_read' | ||
}; | ||
const anApp = new Clarifai.App(null, null, {token: token}); | ||
anApp._config.token() | ||
.then(response => { | ||
expect(response.accessToken).toEqual('foo'); | ||
done(); | ||
}) | ||
.catch(errorHandler.bind(done)); | ||
}); | ||
|
||
it('Sets a token with a string', done => { | ||
const anApp = new Clarifai.App(null, null, {token: 'bar'}); | ||
anApp._config.token() | ||
.then(response => { | ||
expect(response.accessToken).toEqual('bar'); | ||
done(); | ||
}) | ||
.catch(errorHandler.bind(done)); | ||
}); | ||
}); |
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
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,75 @@ | ||
const Clarifai = require('./../src'); | ||
const {errorHandler} = require('./helpers'); | ||
const langConceptId = '的な' + Date.now(); | ||
const beerId = 'beer' + Date.now(); | ||
const ferrariId = 'ferrari' + Date.now(); | ||
|
||
let app; | ||
|
||
describe('Concepts', () => { | ||
const conceptsIds = [ | ||
'porsche' + Date.now(), | ||
'rolls royce' + Date.now(), | ||
'lamborghini' + Date.now(), | ||
langConceptId, | ||
beerId, | ||
ferrariId | ||
]; | ||
|
||
beforeAll(() => { | ||
app = new Clarifai.App( | ||
process.env.CLIENT_ID, | ||
process.env.CLIENT_SECRET, | ||
{ | ||
apiEndpoint: process.env.API_ENDPOINT, | ||
token: process.env.CLIENT_TOKEN | ||
} | ||
); | ||
}); | ||
|
||
it('creates concepts given a list of strings', done => { | ||
app.concepts.create(conceptsIds) | ||
.then(concepts => { | ||
expect(concepts).toBeDefined(); | ||
expect(concepts.length).toBe(conceptsIds.length); | ||
expect(concepts[0].id).toBe(conceptsIds[0]); | ||
expect(concepts[1].id).toBe(conceptsIds[1]); | ||
expect(concepts[2].id).toBe(conceptsIds[2]); | ||
done(); | ||
}) | ||
.catch(errorHandler.bind(done)); | ||
}); | ||
|
||
it('gets concept with id in a different language', done => { | ||
app.concepts.get(langConceptId) | ||
.then(concept => { | ||
expect(concept.id).toBe(langConceptId); | ||
expect(concept.name).toBe(langConceptId); | ||
done(); | ||
}) | ||
.catch(errorHandler.bind(done)); | ||
}); | ||
|
||
it('search concepts', done => { | ||
app.concepts.search('lab*') | ||
.then(concepts => { | ||
expect(concepts.length).toBe(6); | ||
expect(concepts[0].name).toBe('label'); | ||
done(); | ||
}) | ||
.catch(errorHandler.bind(done)); | ||
}); | ||
|
||
it('search concepts in a different language', done => { | ||
app.concepts.search('狗*', 'zh') | ||
.then(concepts => { | ||
expect(concepts.length).toBe(3); | ||
return app.models.delete(); | ||
}) | ||
.then(response => { | ||
expect(response.status).toBeDefined(); | ||
done(); | ||
}) | ||
.catch(errorHandler.bind(done)); | ||
}); | ||
}); |
Oops, something went wrong.