Skip to content

Commit 41e14d3

Browse files
authored
APIC-41 Skip token tests if env vars not present (#110)
1 parent e2c0fc2 commit 41e14d3

File tree

9 files changed

+53
-51
lines changed

9 files changed

+53
-51
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ This will create three folders:
1717
* `npm run watch` - this will do an initial build, then build on any changes to *src*
1818
* `npm run test` - test JS files in the */spec* folder
1919
* tests require the following environment variables to be set:
20-
* `API_KEY`
21-
* `CLIENT_ID`
22-
* `CLIENT_SECRET`
23-
* `APP_ID`
24-
* `USER_ID`
25-
* `SESSION_TOKEN`
20+
* `CLARIFAI_API_KEY`
2621
* `npm run clean` - empty and remove the folders created on build
2722

2823
#### Command line optional params

spec/api-key-spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ const {sampleImages} = require('./test-data');
44

55
describe('API key', () => {
66
it('can initialize an app with an api key', done => {
7-
const anApp = new Clarifai.App({apiKey: process.env.API_KEY});
8-
expect(anApp._config.apiKey).toEqual(process.env.API_KEY);
7+
expect(process.env.CLARIFAI_API_KEY).toBeDefined();
8+
const anApp = new Clarifai.App({apiKey: process.env.CLARIFAI_API_KEY});
9+
expect(anApp._config.apiKey).toEqual(process.env.CLARIFAI_API_KEY);
910
done();
1011
});
1112

1213
it('can make calls with an api key', done => {
13-
const anApp = new Clarifai.App({apiKey: process.env.API_KEY});
14+
const anApp = new Clarifai.App({apiKey: process.env.CLARIFAI_API_KEY});
1415
anApp.models.predict(Clarifai.GENERAL_MODEL, [
1516
{
1617
'url': sampleImages[0]

spec/concepts-spec.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ describe('Concepts', () => {
1717
];
1818

1919
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-
);
20+
app = new Clarifai.App({
21+
apiKey: process.env.CLARIFAI_API_KEY,
22+
apiEndpoint: process.env.API_ENDPOINT
23+
});
2824
});
2925

3026
it('creates concepts given a list of strings', done => {

spec/delete-spec.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ let testModelId = 'vroom-vroom' + d;
1313
describe('Delete Resources', () => {
1414

1515
beforeAll(done => {
16-
app = new Clarifai.App(
17-
process.env.CLIENT_ID,
18-
process.env.CLIENT_SECRET,
19-
{
20-
apiEndpoint: process.env.API_ENDPOINT,
21-
token: process.env.CLIENT_TOKEN
22-
}
23-
);
16+
app = new Clarifai.App({
17+
apiKey: process.env.CLARIFAI_API_KEY,
18+
apiEndpoint: process.env.API_ENDPOINT,
19+
});
2420

2521
app.inputs.create([
2622
{

spec/inputs-search-spec.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@ let lastCount;
2020
describe('Inputs', () => {
2121

2222
beforeAll(done => {
23-
app = new Clarifai.App(
24-
process.env.CLIENT_ID,
25-
process.env.CLIENT_SECRET,
26-
{
27-
apiEndpoint: process.env.API_ENDPOINT,
28-
token: process.env.CLIENT_TOKEN
29-
}
30-
);
23+
app = new Clarifai.App({
24+
apiKey: process.env.CLARIFAI_API_KEY,
25+
apiEndpoint: process.env.API_ENDPOINT
26+
});
3127

3228
app.inputs.delete()
3329
.then(response => {
@@ -560,7 +556,7 @@ describe('Search', () => {
560556

561557
app.inputs.delete()
562558
.then(() => {
563-
return app.models.delete();
559+
return app.models.delete();
564560
})
565561
.then(response => {
566562
expect(response.status).toBeDefined();

spec/models-spec.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ describe('Models', () => {
2424
var testModel;
2525

2626
beforeAll(() => {
27-
app = new Clarifai.App(
28-
process.env.CLIENT_ID,
29-
process.env.CLIENT_SECRET,
30-
{
31-
apiEndpoint: process.env.API_ENDPOINT,
32-
token: process.env.CLIENT_TOKEN
33-
}
34-
);
27+
app = new Clarifai.App({
28+
apiKey: process.env.CLARIFAI_API_KEY,
29+
apiEndpoint: process.env.API_ENDPOINT
30+
});
3531
});
3632

3733
it('Creates a new model', done => {

spec/options-spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ const Clarifai = require('./../src');
22

33
describe('Options', () => {
44
it('can initialize an app with just the options object', done => {
5+
// Skip test if these aren't defined
6+
if (
7+
!process.env.CLIENT_ID ||
8+
!process.env.CLIENT_SECRET
9+
) {
10+
return pending('CLIENT_ID or CLIENT_SECRET not defined');
11+
}
12+
513
const app = new Clarifai.App({clientId: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET});
614
expect(app._config.clientId).toEqual(process.env.CLIENT_ID);
715
done();

spec/session-token-spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ const {sampleImages} = require('./test-data');
55
describe('Session Token', () => {
66

77
it('can initialize an app with a session token, app id and user id', done => {
8+
// Skip test if these aren't defined
9+
if (
10+
!process.env.SESSION_TOKEN ||
11+
!process.env.APP_ID ||
12+
!process.env.USER_ID
13+
) {
14+
return pending('SESSION_TOKEN, APP_ID, or USER_ID not defined');
15+
}
16+
817
const anApp = new Clarifai.App({
918
sessionToken: process.env.SESSION_TOKEN,
1019
appId: process.env.APP_ID,
@@ -15,6 +24,15 @@ describe('Session Token', () => {
1524
});
1625

1726
it('can make calls with a session token', done => {
27+
// Skip test if these aren't defined
28+
if (
29+
!process.env.SESSION_TOKEN ||
30+
!process.env.CLARIFAI_USER_APP_ID ||
31+
!process.env.USER_ID
32+
) {
33+
return pending('SESSION_TOKEN, CLARIFAI_USER_APP_ID, or USER_ID not defined');
34+
}
35+
1836
const anApp = new Clarifai.App({
1937
sessionToken: process.env.SESSION_TOKEN,
2038
appId: process.env.CLARIFAI_USER_APP_ID,

spec/workflow-spec.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ let testWorkflowId;
88

99
describe('Workflow', () => {
1010
beforeAll(function() {
11-
app = new Clarifai.App(
12-
process.env.CLIENT_ID,
13-
process.env.CLIENT_SECRET,
14-
{
15-
apiEndpoint: process.env.API_ENDPOINT,
16-
token: process.env.CLIENT_TOKEN
17-
}
18-
);
19-
})
11+
app = new Clarifai.App({
12+
apiKey: process.env.CLARIFAI_API_KEY,
13+
apiEndpoint: process.env.API_ENDPOINT
14+
});
15+
});
2016

2117
it('Call given workflow id with one input', done => {
2218
testWorkflowId = 'big-bang' + Date.now();

0 commit comments

Comments
 (0)