How to use fetchAll method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

index.js

Source:index.js Github

copy

Full Screen

...57 should.fail();58 } catch (e) {59 e.message.should.equal('foobar');60 }61 const accounts = await Account.fetchAll();62 const authors = await Author.fetchAll();63 const commenters = await Commenter.fetchAll();64 const comments = await Comment.fetchAll();65 const posts = await Post.fetchAll();66 accounts.length.should.equal(1);67 authors.length.should.equal(1);68 commenters.length.should.equal(1);69 comments.length.should.equal(1);70 posts.length.should.equal(1);71 sinon.restore(Model);72 });73 it('should rollback any query on given `transaction` if an error is thrown on model destroy', async () => {74 sinon.stub(Model, 'destroy').throws(new Error('foobar'));75 try {76 await repository.knex.transaction(transaction => Author.forge().save(null, { transacting: transaction })77 .then(() => Author.forge().save(null, { transacting: transaction }))78 .then(author => author.destroy({ transacting: transaction }))79 );80 should.fail();81 } catch (e) {82 e.message.should.equal('foobar');83 }84 const authors = await Author.fetchAll();85 authors.length.should.equal(0);86 sinon.restore(Model);87 });88 it('should delete model and all its dependents', async () => {89 const author = await Author.forge().save();90 const post1 = await Post.forge().save({ authorId: author.get('author_id') });91 const post2 = await Post.forge().save({ authorId: author.get('author_id') });92 const comment1 = await Comment.forge().save({ postId: post1.get('post_id') });93 const comment2 = await Comment.forge().save({ postId: post2.get('post_id') });94 const tag1 = await Tag.forge().save();95 const tag2 = await Tag.forge().save();96 await Account.forge().save({ authorId: author.get('author_id') });97 await Commenter.forge().save({ commentId: comment1.get('comment_id') });98 await Commenter.forge().save({ commentId: comment2.get('comment_id') });99 await TagPost.forge().save({ postId: post1.get('post_id'), tagId: tag1.get('tag_id') });100 await TagPost.forge().save({ postId: post2.get('post_id'), tagId: tag2.get('tag_id') });101 await author.destroy();102 const accounts = await Account.fetchAll();103 const authors = await Author.fetchAll();104 const commenters = await Commenter.fetchAll();105 const comments = await Comment.fetchAll();106 const posts = await Post.fetchAll();107 const tagPosts = await TagPost.fetchAll();108 accounts.length.should.equal(0);109 authors.length.should.equal(0);110 commenters.length.should.equal(0);111 comments.length.should.equal(0);112 posts.length.should.equal(0);113 tagPosts.length.should.equal(0);114 });115 it('should delete queried model and all its dependents', async () => {116 const author = await Author.forge().save({ name: 'foobar' });117 const post1 = await Post.forge().save({ authorId: author.get('author_id') });118 const post2 = await Post.forge().save({ authorId: author.get('author_id') });119 const comment1 = await Comment.forge().save({ postId: post1.get('post_id') });120 const comment2 = await Comment.forge().save({ postId: post2.get('post_id') });121 const tag1 = await Tag.forge().save();122 const tag2 = await Tag.forge().save();123 await Account.forge().save({ authorId: author.get('author_id') });124 await Commenter.forge().save({ commentId: comment1.get('comment_id') });125 await Commenter.forge().save({ commentId: comment2.get('comment_id') });126 await TagPost.forge().save({ postId: post1.get('post_id'), tagId: tag1.get('tag_id') });127 await TagPost.forge().save({ postId: post2.get('post_id'), tagId: tag2.get('tag_id') });128 await Author.forge().where({ name: 'foobar' }).destroy();129 const accounts = await Account.fetchAll();130 const authors = await Author.fetchAll();131 const commenters = await Commenter.fetchAll();132 const comments = await Comment.fetchAll();133 const posts = await Post.fetchAll();134 const tagPosts = await TagPost.fetchAll();135 accounts.length.should.equal(0);136 authors.length.should.equal(0);137 commenters.length.should.equal(0);138 comments.length.should.equal(0);139 posts.length.should.equal(0);140 tagPosts.length.should.equal(0);141 });142 it('should not delete models which are not dependent', async () => {143 const author1 = await Author.forge().save();144 const author2 = await Author.forge().save();145 const post1 = await Post.forge().save({ authorId: author1.get('author_id') });146 const post2 = await Post.forge().save({ authorId: author2.get('author_id') });147 const comment1 = await Comment.forge().save({ postId: post1.get('post_id') });148 const comment2 = await Comment.forge().save({ postId: post2.get('post_id') });149 const tag1 = await Tag.forge().save();150 const tag2 = await Tag.forge().save();151 await Account.forge().save({ authorId: author1.get('author_id') });152 await Account.forge().save({ authorId: author2.get('author_id') });153 await Commenter.forge().save({ commentId: comment1.get('comment_id') });154 await Commenter.forge().save({ commentId: comment2.get('comment_id') });155 await TagPost.forge().save({ postId: post1.get('post_id'), tagId: tag1.get('tag_id') });156 await TagPost.forge().save({ postId: post2.get('post_id'), tagId: tag2.get('tag_id') });157 await author1.destroy();158 const accounts = await Account.fetchAll();159 const authors = await Author.fetchAll();160 const commenters = await Commenter.fetchAll();161 const comments = await Comment.fetchAll();162 const posts = await Post.fetchAll();163 const tagPosts = await TagPost.fetchAll();164 accounts.length.should.equal(1);165 authors.length.should.equal(1);166 commenters.length.should.equal(1);167 comments.length.should.equal(1);168 posts.length.should.equal(1);169 tagPosts.length.should.equal(1);170 });171 it('should call prototype method `destroy` with given `options`', async () => {172 sinon.spy(Model, 'destroy');173 const author = await Author.forge().save();174 await author.destroy({ foo: 'bar' });175 Model.destroy.callCount.should.equal(1);176 Model.destroy.firstCall.args[0].should.have.properties({ foo: 'bar' });177 sinon.restore(Model);...

Full Screen

Full Screen

effects.ts

Source:effects.ts Github

copy

Full Screen

...64 data: data.body,65 });66 const { task_id: taskId } = (getState() as RootStateType).oneTask.data;67 dispatch(OneTaskEffects.refetchOneTask(taskId));68 dispatch(CompletedListEffects.fetchAll({}));69 dispatch(AtWorkListEffects.fetchAll({}));70 dispatch(IncomingListEffects.fetchAll({}));71 dispatch(NotCompletedListEffects.fetchAll({}));72 dispatch(RejectedListEffects.fetchAll({}));73 return response.data.data;74 } catch (e) {75 return rejectWithValue((e as Error).message);76 }77 },78);79export const removeTag = createAsyncThunk(80 'tags/removeTag',81 async (tagId: string, { rejectWithValue, dispatch, getState }) => {82 try {83 const response = await makeRequest<TagResponseType>({84 url: `task/tags/${tagId}`,85 method: 'DELETE',86 });87 const { task_id: taskId } = (getState() as RootStateType).oneTask.data;88 dispatch(OneTaskEffects.refetchOneTask(taskId));89 dispatch(CompletedListEffects.fetchAll({}));90 dispatch(AtWorkListEffects.fetchAll({}));91 dispatch(IncomingListEffects.fetchAll({}));92 dispatch(NotCompletedListEffects.fetchAll({}));93 dispatch(RejectedListEffects.fetchAll({}));94 return response.data.data;95 } catch (e) {96 return rejectWithValue((e as Error).message);97 }98 },99);100export const assignTagToTask = createAsyncThunk(101 'tags/assignTagToTask',102 async (103 data: { body: { task_tag_id: string }; task_id: string },104 { rejectWithValue, dispatch },105 ) => {106 try {107 const response = await makeRequest<TagAssignResponseType>({108 url: `task/tasks/${data.task_id}/tag-assign`,109 method: 'POST',110 data: data.body,111 });112 // Добавить вызов обновления задачи113 // eslint-disable-next-line default-case114 switch (response.data.data.status.task_status_id) {115 case StatusesTypes.statusesId.completed:116 dispatch(CompletedListEffects.fetchAll({}));117 break;118 case StatusesTypes.statusesId.created:119 dispatch(IncomingListEffects.fetchAll({}));120 break;121 case StatusesTypes.statusesId.inWork:122 dispatch(AtWorkListEffects.fetchAll({}));123 break;124 case StatusesTypes.statusesId.notCompleted:125 dispatch(NotCompletedListEffects.fetchAll({}));126 break;127 case StatusesTypes.statusesId.rejected:128 dispatch(RejectedListEffects.fetchAll({}));129 break;130 }131 dispatch(OneTaskActions.changeData(response.data.data));132 dispatch(HistoryEffects.fetchHistory(data.task_id));133 return response.data.data;134 } catch (e) {135 return rejectWithValue((e as Error).message);136 }137 },138);139export const unAssignTagFromTask = createAsyncThunk(140 'tags/unAssignTagFromTask',141 async (142 data: { body: { task_tag_id: string }; task_id: string },143 { rejectWithValue, dispatch },144 ) => {145 try {146 const response = await makeRequest<TagAssignResponseType>({147 url: `task/tasks/${data.task_id}/tag-unassign`,148 method: 'POST',149 data: data.body,150 });151 // eslint-disable-next-line default-case152 switch (response.data.data.status.task_status_id) {153 case StatusesTypes.statusesId.completed:154 dispatch(CompletedListEffects.fetchAll({}));155 break;156 case StatusesTypes.statusesId.created:157 dispatch(IncomingListEffects.fetchAll({}));158 break;159 case StatusesTypes.statusesId.inWork:160 dispatch(AtWorkListEffects.fetchAll({}));161 break;162 case StatusesTypes.statusesId.notCompleted:163 dispatch(NotCompletedListEffects.fetchAll({}));164 break;165 case StatusesTypes.statusesId.rejected:166 dispatch(RejectedListEffects.fetchAll({}));167 break;168 }169 dispatch(OneTaskActions.changeData(response.data.data));170 dispatch(HistoryEffects.fetchHistory(data.task_id));171 return response.data.data;172 } catch (e) {173 return rejectWithValue((e as Error).message);174 }175 },...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pact-foundation-pact automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful