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 error when a not yet inserted job is updated #7196

Merged
merged 7 commits into from
Feb 18, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ___
- IMPROVE: Parse Server is from now on continuously tested against all recent Node.js versions that have not reached their end-of-life support date. [7161](https://github.com/parse-community/parse-server/pull/7177). Thanks to [Manuel Trezza](https://github.com/mtrezza).
- IMPROVE: Optimize queries on classes with pointer permissions. [#7061](https://github.com/parse-community/parse-server/pull/7061). Thanks to [Pedro Diaz](https://github.com/pdiaz)
- IMPROVE: Parse Server will from now on be continuously tested against all relevant Postgres versions (minor versions). Added Postgres compatibility table to Parse Server docs. [#7176](https://github.com/parse-community/parse-server/pull/7176). Thanks to [Corey Baker](https://github.com/cbaker6).
- FIX: Fix error when a not yet inserted job is updated [#7196](https://github.com/parse-community/parse-server/pull/7196). Thanks to [Antonio Davi Macedo Coelho de Castro](https://github.com/davimacedo).
- FIX: request.context for afterFind triggers. [#7078](https://github.com/parse-community/parse-server/pull/7078). Thanks to [dblythy](https://github.com/dblythy)
- FIX: Winston Logger interpolating stdout to console [#7114](https://github.com/parse-community/parse-server/pull/7114). Thanks to [dplewis](https://github.com/dplewis)

Expand Down
151 changes: 79 additions & 72 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,9 @@ describe('Cloud Code', () => {
describe('cloud jobs', () => {
it('should define a job', done => {
expect(() => {
Parse.Cloud.job('myJob', () => {});
Parse.Cloud.job('myJob', ({ message }) => {
message('Hello, world!!!');
});
}).not.toThrow();

request({
Expand All @@ -1559,15 +1561,19 @@ describe('Cloud Code', () => {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
},
}).then(
() => {
done();
},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return jobStatus.get('finishedAt') && jobStatus.get('message') === 'Hello, world!!!';
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should not run without master key', done => {
Expand Down Expand Up @@ -1602,7 +1608,6 @@ describe('Cloud Code', () => {
expect(typeof req.jobId).toBe('string');
expect(typeof req.message).toBe('function');
expect(typeof res).toBe('undefined');
done();
});
}).not.toThrow();

Expand All @@ -1613,13 +1618,19 @@ describe('Cloud Code', () => {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
},
}).then(
() => {},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return jobStatus.get('finishedAt');
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should run with master key basic auth', done => {
Expand All @@ -1630,25 +1641,30 @@ describe('Cloud Code', () => {
expect(typeof req.jobId).toBe('string');
expect(typeof req.message).toBe('function');
expect(typeof res).toBe('undefined');
done();
});
}).not.toThrow();

request({
method: 'POST',
url: `http://${Parse.applicationId}:${Parse.masterKey}@localhost:8378/1/jobs/myJob`,
}).then(
() => {},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return jobStatus.get('finishedAt');
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should set the message / success on the job', done => {
Parse.Cloud.job('myJob', req => {
const promise = req
return req
.message('hello')
.then(() => {
return getJobStatus(req.jobId);
Expand All @@ -1657,21 +1673,6 @@ describe('Cloud Code', () => {
expect(jobStatus.get('message')).toEqual('hello');
expect(jobStatus.get('status')).toEqual('running');
});
promise
.then(() => {
return getJobStatus(req.jobId);
})
.then(jobStatus => {
expect(jobStatus.get('message')).toEqual('hello');
expect(jobStatus.get('status')).toEqual('succeeded');
done();
})
.catch(err => {
console.error(err);
jfail(err);
done();
});
return promise;
});

request({
Expand All @@ -1681,32 +1682,28 @@ describe('Cloud Code', () => {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
},
}).then(
() => {},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return (
jobStatus.get('finishedAt') &&
jobStatus.get('message') === 'hello' &&
jobStatus.get('status') === 'succeeded'
);
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should set the failure on the job', done => {
Parse.Cloud.job('myJob', req => {
const promise = Promise.reject('Something went wrong');
new Promise(resolve => setTimeout(resolve, 200))
.then(() => {
return getJobStatus(req.jobId);
})
.then(jobStatus => {
expect(jobStatus.get('message')).toEqual('Something went wrong');
expect(jobStatus.get('status')).toEqual('failed');
done();
})
.catch(err => {
jfail(err);
done();
});
return promise;
Parse.Cloud.job('myJob', () => {
return Promise.reject('Something went wrong');
});

request({
Expand All @@ -1716,13 +1713,23 @@ describe('Cloud Code', () => {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
},
}).then(
() => {},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return (
jobStatus.get('finishedAt') &&
jobStatus.get('message') === 'Something went wrong' &&
jobStatus.get('status') === 'failed'
);
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should set the failure message on the job error', async () => {
Expand Down