Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no parameters issue with createJob #759

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/api-helper/misc/job/createJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export async function createJob<T extends ParameterType>(details: JobDetails<T>,
data.secrets = [];

const cmd = typeof command === "string" ? command : command.name;
const params = Array.isArray(parameters) ? parameters : [parameters];
let params = (Array.isArray(parameters) ? parameters : [parameters]).filter(p => !!p);
if (params.length === 0) {
params = [{}] as T[];
}

const result = await ctx.graphClient.mutate<CreateJob.Mutation, CreateJob.Variables>({
name: "CreateJob",
Expand Down
34 changes: 34 additions & 0 deletions test/api-helper/misc/job/createJob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,38 @@ describe("createJob", () => {
assert.deepStrictEqual(result, { id: "123456" });
});

it("should allow an empty parameter array", async () => {

const result = await createJob({
command: "TestCommand",
registration: "@atomist/sdm-test",
description: "This is a test command",
parameters: [],
}, {
context: {
name: "@atomist/sdm-test",
},
graphClient: {
mutate: async options => {
const vars = options.variables;
assert.strictEqual(vars.name, "TestCommand");
assert.strictEqual(vars.description, "This is a test command");
assert.strictEqual(vars.owner, "@atomist/sdm-test");
assert.strictEqual(vars.tasks.length, 1);
assert.strictEqual(vars.tasks[0].name, "TestCommand");
assert.strictEqual(vars.tasks[0].data, JSON.stringify({
type: JobTaskType.Command,
parameters: { },
}));
return {
createAtmJob: { id: "123456" },
} as any;
},
} as any,
} as any);

assert.deepStrictEqual(result, { id: "123456" });

});

});