Fix tests
This commit is contained in:
@@ -43,11 +43,7 @@ describe("Action", () => {
|
|||||||
it('creates release if no release exists to update', async () => {
|
it('creates release if no release exists to update', async () => {
|
||||||
const action = createAction(true, true)
|
const action = createAction(true, true)
|
||||||
const error = {
|
const error = {
|
||||||
errors: [
|
status: 404
|
||||||
{
|
|
||||||
code: 'missing'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
getMock.mockRejectedValue(error)
|
getMock.mockRejectedValue(error)
|
||||||
|
|
||||||
|
|||||||
@@ -14,15 +14,16 @@ describe('ErrorMessage', () => {
|
|||||||
code: 'already_exists',
|
code: 'already_exists',
|
||||||
resource: 'release'
|
resource: 'release'
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
status: 422
|
||||||
}
|
}
|
||||||
|
|
||||||
it('does not have error', ()=> {
|
it('does not have error', () => {
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
expect(errorMessage.hasErrorWithCode('missing_field')).toBeFalsy()
|
expect(errorMessage.hasErrorWithCode('missing_field')).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has error', ()=> {
|
it('has error', () => {
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
expect(errorMessage.hasErrorWithCode('missing')).toBeTruthy()
|
expect(errorMessage.hasErrorWithCode('missing')).toBeTruthy()
|
||||||
})
|
})
|
||||||
@@ -41,22 +42,30 @@ describe('ErrorMessage', () => {
|
|||||||
code: 'already_exists',
|
code: 'already_exists',
|
||||||
resource: 'release'
|
resource: 'release'
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
status: 422
|
||||||
}
|
}
|
||||||
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
|
|
||||||
const expectedString = "something bad happened\nErrors:\n- release does not exist.\n- release already exists."
|
const expectedString = "Error 422: something bad happened\nErrors:\n- release does not exist.\n- release already exists."
|
||||||
expect(errorMessage.toString()).toBe(expectedString)
|
expect(errorMessage.toString()).toBe(expectedString)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('generates message without errors', () => {
|
it('generates message without errors', () => {
|
||||||
const error = {
|
const error = {
|
||||||
message: 'something bad happened'
|
message: 'something bad happened',
|
||||||
|
status: 422
|
||||||
}
|
}
|
||||||
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
|
|
||||||
expect(errorMessage.toString()).toBe('something bad happened')
|
expect(errorMessage.toString()).toBe('Error 422: something bad happened')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('provides error status', () => {
|
||||||
|
const error = { status: 404 }
|
||||||
|
const errorMessage = new ErrorMessage(error)
|
||||||
|
expect(errorMessage.status).toBe(404)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -27,16 +27,22 @@ class Action {
|
|||||||
}
|
}
|
||||||
createOrUpdateRelease() {
|
createOrUpdateRelease() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
if (this.inputs.allowUpdates) {
|
||||||
return yield this.createRelease();
|
try {
|
||||||
|
const getResponse = yield this.releases.getByTag(this.inputs.tag);
|
||||||
|
return yield this.updateRelease(getResponse.data.id);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (this.noRelease(error)) {
|
||||||
|
return yield this.createRelease();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
else {
|
||||||
if (this.releaseAlreadyExisted(error) && this.inputs.allowUpdates) {
|
return yield this.createRelease();
|
||||||
return this.updateRelease();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -46,14 +52,12 @@ class Action {
|
|||||||
return response.data.upload_url;
|
return response.data.upload_url;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
releaseAlreadyExisted(error) {
|
noRelease(error) {
|
||||||
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
|
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
|
||||||
return errorMessage.hasErrorWithCode('already_exists');
|
return errorMessage.status == 404;
|
||||||
}
|
}
|
||||||
updateRelease() {
|
updateRelease(id) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const getResponse = yield this.releases.getByTag(this.inputs.tag);
|
|
||||||
const id = getResponse.data.id;
|
|
||||||
const response = yield this.releases.update(id, this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
|
const response = yield this.releases.update(id, this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
|
||||||
return response.data.upload_url;
|
return response.data.upload_url;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user