|
| 1 | +const Clarifai = require('./../src'); |
| 2 | +const {errorHandler} = require('./helpers'); |
| 3 | +const langConceptId = '的な' + Date.now(); |
| 4 | +const beerId = 'beer' + Date.now(); |
| 5 | +const ferrariId = 'ferrari' + Date.now(); |
| 6 | + |
| 7 | +let app; |
| 8 | + |
| 9 | +describe('Concepts', () => { |
| 10 | + const conceptsIds = [ |
| 11 | + 'porsche' + Date.now(), |
| 12 | + 'rolls royce' + Date.now(), |
| 13 | + 'lamborghini' + Date.now(), |
| 14 | + langConceptId, |
| 15 | + beerId, |
| 16 | + ferrariId |
| 17 | + ]; |
| 18 | + |
| 19 | + beforeAll(() => { |
| 20 | + app = new Clarifai.App( |
| 21 | + process.env.CLIENT_ID, |
| 22 | + process.env.CLIENT_SECRET, |
| 23 | + { |
| 24 | + apiEndpoint: process.env.API_ENDPOINT, |
| 25 | + token: process.env.CLIENT_TOKEN |
| 26 | + } |
| 27 | + ); |
| 28 | + }); |
| 29 | + |
| 30 | + it('creates concepts given a list of strings', done => { |
| 31 | + app.concepts.create(conceptsIds) |
| 32 | + .then(concepts => { |
| 33 | + expect(concepts).toBeDefined(); |
| 34 | + expect(concepts.length).toBe(conceptsIds.length); |
| 35 | + expect(concepts[0].id).toBe(conceptsIds[0]); |
| 36 | + expect(concepts[1].id).toBe(conceptsIds[1]); |
| 37 | + expect(concepts[2].id).toBe(conceptsIds[2]); |
| 38 | + done(); |
| 39 | + }) |
| 40 | + .catch(errorHandler.bind(done)); |
| 41 | + }); |
| 42 | + |
| 43 | + it('gets concept with id in a different language', done => { |
| 44 | + app.concepts.get(langConceptId) |
| 45 | + .then(concept => { |
| 46 | + expect(concept.id).toBe(langConceptId); |
| 47 | + expect(concept.name).toBe(langConceptId); |
| 48 | + done(); |
| 49 | + }) |
| 50 | + .catch(errorHandler.bind(done)); |
| 51 | + }); |
| 52 | + |
| 53 | + it('search concepts', done => { |
| 54 | + app.concepts.search('lab*') |
| 55 | + .then(concepts => { |
| 56 | + expect(concepts.length).toBe(6); |
| 57 | + expect(concepts[0].name).toBe('label'); |
| 58 | + done(); |
| 59 | + }) |
| 60 | + .catch(errorHandler.bind(done)); |
| 61 | + }); |
| 62 | + |
| 63 | + it('search concepts in a different language', done => { |
| 64 | + app.concepts.search('狗*', 'zh') |
| 65 | + .then(concepts => { |
| 66 | + expect(concepts.length).toBe(3); |
| 67 | + return app.models.delete(); |
| 68 | + }) |
| 69 | + .then(response => { |
| 70 | + expect(response.status).toBeDefined(); |
| 71 | + done(); |
| 72 | + }) |
| 73 | + .catch(errorHandler.bind(done)); |
| 74 | + }); |
| 75 | +}); |
0 commit comments