Skip to content

Commit 6a46ecc

Browse files
acanedoAlan Canedo Zarazua
andauthored
DEV-297 - Updated integration tests to be more automatic given env variables (#28)
* DEV-297 - Updated integration tests to be more automatic given env variables * code clean up and added TEST.md * lint * addressed comments * addressed comments, changed bogus emails to @example.com * address comments added a way to delete the test orgs after a test Co-authored-by: Alan Canedo Zarazua <[email protected]>
1 parent a0d402f commit 6a46ecc

19 files changed

+548
-253
lines changed

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# `.env.example` DO NOT use this file, rather copy into a new file called `.env` and fill in your actual values and secrets.
2+
# Never commit an `.env` file to a repository.
3+
4+
ALGORITHMIA_API_ADDRESS=anAlgorithmiaAPIAddress
5+
ALGORITHMIA_DEFAULT_API_KEY=yourAlgorithmiaAPIKeyHashSecret
6+
7+
# Variables for testing
8+
ALGORITHMIA_TEST_ADMIN_API_KEY=anAlgorithmiaAdminAPIKeySecret
9+
ALGORITHMIA_TEST_API_ADDRESS=aTestingEnvironmentAlgorithmiaAPIAddress
10+
ALGORITHMIA_TEST_DEFAULT_API_KEY=yourAlgorithmiaAPIkeyHashSecret
11+
ALGORITHMIA_TEST_USERNAME=yourAlgorithmiaUserName

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules/
2-
2+
.env
33
/lib

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ test:
1313
script:
1414
- npm install typescript -g && npm install @types/node
1515
- npx tsc
16-
- if [ -z $ALGORITHMIA_DEFAULT_API_KEY ]; then echo "Algorithmia API key not defined"; exit 1; fi
16+
- if [ -z $ALGORITHMIA_TEST_DEFAULT_API_KEY ]; then echo "Algorithmia API key not defined"; exit 1; fi
1717
- npm test --detectOpenHandles

NahDawg.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ Install it for your project by adding `algorithmia` to your package.json:
1414
npm install --save algorithmia
1515
```
1616

17-
Then instantiate an Algorithmia client using your API key:
17+
Set runtime environment variables by creating `.env` file in the root directory with the following keys
18+
19+
---
20+
21+
|Name|Value|Purpose|
22+
|-|-|-|
23+
|ALGORITHMIA_API_ADDRESS|`<key for Algorithmia api url>`|Optional, will default to https://api.algorithmia.com|
24+
|ALGORITHMIA_DEFAULT_API_KEY|`<secret key to run Algorithmia api>`|Required for algorithmia client|
25+
26+
Then instantiate an Algorithmia client using your API key environment variables:
1827

1928
```javascript
2029
const algorithmia = require('algorithmia');

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"compile:watch": "tsc -w",
1515
"prepare": "npm run compile",
1616
"prepublishOnly": "npm test --detectOpenHandles",
17-
"lint": "eslint ./src/**/*.{js,ts} --quiet",
17+
"lint": "eslint ./src/**/*.{js,ts} ./test/**/*.{js,ts,test.ts,test.js} --quiet",
1818
"lint:fix": "npm run lint -- --fix",
1919
"test": "jest"
2020
},
@@ -33,6 +33,7 @@
3333
"@typescript-eslint/eslint-plugin": "^4.22.1",
3434
"@typescript-eslint/parser": "^4.22.1",
3535
"babel-jest": "^26.6.3",
36+
"dotenv": "^10.0.0",
3637
"eslint": "^7.26.0",
3738
"eslint-config-prettier": "^7.2.0",
3839
"eslint-plugin-prettier": "^3.4.0",

src/Algorithm.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,6 @@ class Algorithm {
3333
this.self_link = self_link;
3434
this.resource_type = resource_type;
3535
}
36-
37-
//for testing
38-
createTestAlgo() {
39-
const requestObject = {
40-
details: {
41-
label: 'My First Algorithm',
42-
},
43-
name: 'my_first_algorithm',
44-
settings: {
45-
environment: 'cpu',
46-
language: 'python3-1',
47-
license: 'apl',
48-
network_access: 'full',
49-
pipeline_enabled: true,
50-
source_visibility: 'closed',
51-
},
52-
};
53-
return requestObject;
54-
}
5536
}
5637

5738
class Details {

src/AlgorithmiaClient.ts

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { Input } from './ContentTypeHelper';
44
import { DataFile, DataDir } from './Data';
55
import { URLSearchParams } from 'url';
66
import { Organization, OrgType, OrgTypes } from './Algorithm';
7+
import dotenv from 'dotenv';
8+
dotenv.config();
79

810
class AlgorithmiaClient {
911
private defaultApiAddress = 'https://api.algorithmia.com';
@@ -23,16 +25,15 @@ class AlgorithmiaClient {
2325
apiAddress ||
2426
process.env.ALGORITHMIA_API_ADDRESS ||
2527
this.defaultApiAddress;
26-
this.key = key || process.env.ALGORITHMIA_API_KEY || '';
28+
this.key = key || process.env.ALGORITHMIA_DEFAULT_API_KEY || '';
2729
if (key) {
2830
if (key.startsWith('Simple ')) {
2931
this.key = key;
3032
} else {
3133
this.key = 'Simple ' + key;
3234
}
33-
} else {
34-
this.key = '';
3535
}
36+
3637
this.httpClient = new HttpClient(this.key);
3738
}
3839

@@ -60,6 +61,41 @@ class AlgorithmiaClient {
6061
);
6162
}
6263

64+
/**
65+
* Get an Algorithm build object from this client
66+
* @param userName the algorithmia user name
67+
* @param algoName the name of the algorithm
68+
* @return an Algorithm build object for the specified algorithm
69+
*/
70+
buildAlgo(userName: string, algoName: string) {
71+
return this.httpClient.post(
72+
`${this.apiAddress}${this.algorithmsPrefix}/${userName}/${algoName}/compile`,
73+
{},
74+
'application/json'
75+
);
76+
}
77+
78+
/**
79+
* Get an Algorithm published object from this client
80+
* @param userName the algorithmia user name
81+
* @param algoName the name of the algorithm
82+
* @return an Algorithm published object for the specified algorithm
83+
*/
84+
publishAlgo(userName: string, algoName: string) {
85+
return this.httpClient.post(
86+
`${this.apiAddress}${this.algorithmsPrefix}/${userName}/${algoName}/version`,
87+
{
88+
settings: {
89+
algorithm_callability: 'private',
90+
insights_enabled: false,
91+
royalty_microcredits: 0,
92+
},
93+
version_info: { version_type: 'revision' },
94+
},
95+
'application/json'
96+
);
97+
}
98+
6399
/**
64100
* List algorithm versions from this client
65101
* @param userName the users Algorithmia user name
@@ -130,8 +166,9 @@ class AlgorithmiaClient {
130166
* @return a BuildLogs object for the specified algorithm
131167
*/
132168
getAlgoBuildLogs(userName: string, algoName: string, buildId: string) {
133-
const path = `${this.algorithmsPrefix}/${userName}/${algoName}/builds/${buildId}/logs`;
134-
return this.httpClient.get(`${this.apiAddress}${path}`);
169+
return this.httpClient.get(
170+
`${this.apiAddress}${this.algorithmsPrefix}/${userName}/${algoName}/builds/${buildId}/logs`
171+
);
135172
}
136173

137174
/**
@@ -239,6 +276,17 @@ class AlgorithmiaClient {
239276
);
240277
}
241278

279+
/**
280+
* Delete an organization from this client
281+
* @param orgName the organization name
282+
* @return an empty response
283+
*/
284+
deleteOrganization(orgName: string) {
285+
return this.httpClient.delete(
286+
`${this.apiAddress}${this.organizationsPrefix}/${orgName}`
287+
);
288+
}
289+
242290
clone(obj: Input) {
243291
return JSON.parse(JSON.stringify(obj));
244292
}

src/ContentTypeHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface Json {
2-
[key: string]: number | string | null | Json;
2+
[key: string]: number | string | null | Json | boolean;
33
}
44

55
export type Input = Json | string | Buffer;

0 commit comments

Comments
 (0)