Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
SwinX committed Mar 23, 2017
1 parent f94843a commit d451c8e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
15 changes: 9 additions & 6 deletions test/unit/zendesk-uploader/article-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ describe('ArticleUploader', () => {
it('should reject the promise with an error when the api returns an error', () => {
const article = testUtils.createArticle({isNew: true});
const uploader = createUploader_(article);
const error = new Error('error');

zendeskClient.articles.create.rejects('error');
zendeskClient.articles.create.rejects(error);

return expect(uploader.create())
.to.be.rejectedWith('error');
.to.be.rejectedWith(error);
});

it('should set `locale` metadata to the request', () => {
Expand Down Expand Up @@ -389,11 +390,12 @@ describe('ArticleUploader', () => {
it('should reject the promise when the article update API returns an error', () => {
const article = testUtils.createArticle({isChanged: true});
const uploader = createUploader_(article);
const error = new Error('error');

zendeskClient.articles.update.rejects('error');
zendeskClient.articles.update.rejects(error);

return expect(uploader.sync())
.to.be.rejectedWith('error');
.to.be.rejectedWith(error);
});

it('should set the article `position` to the request if one is provided', () => {
Expand Down Expand Up @@ -495,11 +497,12 @@ describe('ArticleUploader', () => {
it('should reject the promise when the translations API returns an error', () => {
const article = testUtils.createArticle({isChanged: true});
const uploader = createUploader_(article);
const error = new Error('error');

zendeskClient.translations.updateForArticle.rejects('error');
zendeskClient.translations.updateForArticle.rejects(error);

return expect(uploader.sync())
.to.be.rejectedWith('error');
.to.be.rejectedWith(error);
});

it('should update the translation for the correct locale', () => {
Expand Down
20 changes: 12 additions & 8 deletions test/unit/zendesk-uploader/category-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ describe('CategoryUploader', () => {
it('should reject the promise when the create category API returns an error', () => {
const category = testUtils.createCategory({isNew: true});
const uploader = createUploader_(category);
const error = new Error('error');

zendeskClient.categories.create.rejects('error');
zendeskClient.categories.create.rejects(error);

return expect(uploader.create())
.to.be.rejectedWith('error');
.to.be.rejectedWith(error);
});

it('should set `locale` metadata to the request', () => {
Expand Down Expand Up @@ -188,10 +189,11 @@ describe('CategoryUploader', () => {
it('should reject with an error if a section creation returns an error', () => {
const category = testUtils.createCategory({isNew: true});
const uploader = createUploader_(category);
const error = new Error('error');

SectionUploader.prototype.create.rejects('error');
SectionUploader.prototype.create.rejects(error);

return expect(uploader.create()).to.be.rejectedWith('error');
return expect(uploader.create()).to.be.rejectedWith(error);
});
});

Expand Down Expand Up @@ -258,10 +260,11 @@ describe('CategoryUploader', () => {
it('should reject the promise when the update category API returns an error', () => {
const category = testUtils.createCategory({isChanged: true});
const uploader = createUploader_(category);
const error = new Error('error');

zendeskClient.categories.update.rejects('error');
zendeskClient.categories.update.rejects(error);

return expect(uploader.sync()).to.be.rejectedWith('error');
return expect(uploader.sync()).to.be.rejectedWith(error);
});

it('should set the category `position` to the request if one is provided', () => {
Expand Down Expand Up @@ -323,11 +326,12 @@ describe('CategoryUploader', () => {
it('should reject the promise when the translation API returns an error', () => {
const category = testUtils.createCategory({isChanged: true});
const uploader = createUploader_(category);
const error = new Error('error');

zendeskClient.translations.updateForCategory.rejects('error');
zendeskClient.translations.updateForCategory.rejects(error);

return expect(uploader.sync())
.to.be.rejectedWith('error');
.to.be.rejectedWith(error);
});

it('should update the translation for the correct locale', () => {
Expand Down
5 changes: 3 additions & 2 deletions test/unit/zendesk-uploader/deleter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ describe('Deleter', () => {
it('should reject with an error when the API returns an error', () => {
const category = testUtils.createCategory();
const deleter = createDeleter_(category);
const error = new Error('error');

zendeskClient.articles.listByCategory.resolves([{id: 123456}]);
zendeskClient.articles.delete.rejects('error');
zendeskClient.articles.delete.rejects(error);

return expect(deleter.delete()).to.be.rejectedWith('error');
return expect(deleter.delete()).to.be.rejectedWith(error);
});

it('should log delete action', () => {
Expand Down
30 changes: 18 additions & 12 deletions test/unit/zendesk-uploader/section-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ describe('SectionUploader', () => {
it('should reject the promise when the create sections API returns an error', () => {
const section = testUtils.createSection({isNew: true});
const uploader = createUploader_(section);
const error = new Error('error');

zendeskClient.sections.create.rejects('error');
zendeskClient.sections.create.rejects(error);

return expect(uploader.create()).to.be.rejectedWith('error');
return expect(uploader.create()).to.be.rejectedWith(error);
});

it('should set `locale` metadata to the request', () => {
Expand Down Expand Up @@ -159,10 +160,11 @@ describe('SectionUploader', () => {
it('should reject with an error if an article upload returns an error', () => {
const section = testUtils.createSection({isNew: true});
const uploader = createUploader_(section);
const error = new Error('error');

ArticleUploader.prototype.create.rejects('error');
ArticleUploader.prototype.create.rejects(error);

return expect(uploader.create()).to.be.rejectedWith('error');
return expect(uploader.create()).to.be.rejectedWith(error);
});
});

Expand Down Expand Up @@ -215,11 +217,12 @@ describe('SectionUploader', () => {
it('should reject the promise when the update section update API returns an error', () => {
const section = testUtils.createSection({isChanged: true});
const uploader = createUploader_(section);
const error = new Error('error');

zendeskClient.sections.update.rejects('error');
zendeskClient.sections.update.rejects(error);

return expect(uploader.sync())
.to.be.rejectedWith('error');
.to.be.rejectedWith(error);
});

it('should update the correct section zendeskId', () => {
Expand Down Expand Up @@ -281,10 +284,11 @@ describe('SectionUploader', () => {
it('should reject the promise when the translations API returns an error', () => {
const section = testUtils.createSection({isChanged: true});
const uploader = createUploader_(section);
const error = new Error('error');

zendeskClient.translations.updateForSection.rejects('error');
zendeskClient.translations.updateForSection.rejects(error);

return expect(uploader.sync()).to.be.rejectedWith('error');
return expect(uploader.sync()).to.be.rejectedWith(error);
});

it('should update the translation for the correct zendeskId', () => {
Expand Down Expand Up @@ -380,10 +384,11 @@ describe('SectionUploader', () => {
}
});
const uploader = createUploader_(section);
const error = new Error('error');

zendeskClient.accesspolicies.update.rejects('error');
zendeskClient.accesspolicies.update.rejects(error);

return expect(uploader.sync()).to.be.rejectedWith('error');
return expect(uploader.sync()).to.be.rejectedWith(error);
});

it('should set the `viewable_by` property to the request', () => {
Expand Down Expand Up @@ -491,10 +496,11 @@ describe('SectionUploader', () => {
it('should reject with an error if an article sync returns an error', () => {
const section = testUtils.createSection();
const uploader = createUploader_(section);
const error = new Error('error');

ArticleUploader.prototype.sync.rejects('error');
ArticleUploader.prototype.sync.rejects(error);

return expect(uploader.sync()).to.be.rejectedWith('error');
return expect(uploader.sync()).to.be.rejectedWith(error);
});
});
});
Expand Down

0 comments on commit d451c8e

Please sign in to comment.