Skip to content

Commit ef13d8c

Browse files
committed
test(nx-heroku): add unit tests for webhooks and config vars tables parsers
1 parent 51888a6 commit ef13d8c

File tree

4 files changed

+84
-4
lines changed

4 files changed

+84
-4
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { parseConfigVarsTable } from './config-vars';
2+
3+
const configVarsTable = [
4+
'CLUSTER_ENABLED: true',
5+
'DISK_STORAGE_TRESHOLD: 161061273600',
6+
'EVENT_LOOP_DELAY_THRESHOLD: 100',
7+
'HOSTNAME: 0.0.0.0',
8+
'LOG_CONCURRENCY: true',
9+
'MAX_PAYLOAD_SIZE: 1',
10+
'MEMORY_RSS_TRESHOLD:',
11+
];
12+
13+
const configVars = {
14+
CLUSTER_ENABLED: 'true',
15+
DISK_STORAGE_TRESHOLD: '161061273600',
16+
EVENT_LOOP_DELAY_THRESHOLD: '100',
17+
HOSTNAME: '0.0.0.0',
18+
LOG_CONCURRENCY: 'true',
19+
MAX_PAYLOAD_SIZE: '1',
20+
MEMORY_RSS_TRESHOLD: '',
21+
};
22+
23+
describe('ConfigVars', () => {
24+
it('parseConfigVarsTable - should return a valid Variables object from a table', () => {
25+
const result = parseConfigVarsTable(configVarsTable);
26+
expect(result).toEqual(configVars);
27+
});
28+
});

packages/nx-heroku/src/executors/common/heroku/config-vars.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ export function serializeConfigVars(
4646
variables: Variables,
4747
quote: ConfigVarQuote = `'`
4848
): SerializedConfigVar[] {
49-
return Object.entries(variables).reduce((acc, [key, value]) => {
50-
acc.push(serializeConfigVar(key, value, quote));
51-
return acc;
52-
}, []);
49+
return Object.entries(variables).map(([key, value]) =>
50+
serializeConfigVar(key, value, quote)
51+
);
5352
}
5453

5554
export async function setConfigVars(options: {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { parseWebhooksTable, Webhook } from './webhooks';
2+
3+
const webhooksTable = [
4+
'1965e28c-b99f-4c14-a64c-582efc7667ae https://webhook-handler.io/receive api:build,dyno sync',
5+
'682df0e5-67f8-4a3b-a71d-78451470b997 https://webhook-handler.io/receive api:build,api:release,dyno sync',
6+
'5541c980-0835-4063-bc70-9a11d5b8a016 https://webhook-handler.io/receive api:build,api:release,dyno notify',
7+
'bffc659a-d802-4761-86d5-7f343c135eca https://webhook-handler.io/receive api:addon sync',
8+
'9caf5cfb-ceac-4512-b197-fab47b3629f2 https://webhook-handler.io/receive api:formation sync',
9+
];
10+
11+
const webhooks: Webhook[] = [
12+
{
13+
id: '1965e28c-b99f-4c14-a64c-582efc7667ae',
14+
url: 'https://webhook-handler.io/receive',
15+
include: 'api:build,dyno',
16+
level: 'sync',
17+
},
18+
{
19+
id: '682df0e5-67f8-4a3b-a71d-78451470b997',
20+
url: 'https://webhook-handler.io/receive',
21+
include: 'api:build,api:release,dyno',
22+
level: 'sync',
23+
},
24+
{
25+
id: '5541c980-0835-4063-bc70-9a11d5b8a016',
26+
url: 'https://webhook-handler.io/receive',
27+
include: 'api:build,api:release,dyno',
28+
level: 'notify',
29+
},
30+
{
31+
id: 'bffc659a-d802-4761-86d5-7f343c135eca',
32+
url: 'https://webhook-handler.io/receive',
33+
include: 'api:addon',
34+
level: 'sync',
35+
},
36+
{
37+
id: '9caf5cfb-ceac-4512-b197-fab47b3629f2',
38+
url: 'https://webhook-handler.io/receive',
39+
include: 'api:formation',
40+
level: 'sync',
41+
},
42+
];
43+
44+
describe('Webhooks', () => {
45+
it('parseWebhooksTable - should return a valid Webhook objects array from a table', () => {
46+
const result = parseWebhooksTable(webhooksTable);
47+
expect(result).toEqual(webhooks);
48+
});
49+
});

packages/nx-heroku/src/executors/deploy/executor.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ describe('Deploy Executor', () => {
131131
expect(herokuDeployService.close).toBeCalled();
132132
});
133133

134+
// TODO: test
135+
// validateOptions
136+
// setEnvironmentVariables
137+
// setupHeroku
134138
it('should instantiate the heroku app factory', async () => {
135139
options.config = ['development', 'production'];
136140
herokuDeployService['validateOptions'] = jest.fn();

0 commit comments

Comments
 (0)