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

feat: add message endpoint, implement e2e test #4

Merged
merged 4 commits into from
Aug 9, 2024

Conversation

dagmawig
Copy link
Collaborator

@dagmawig dagmawig commented Jul 2, 2024

working on issue #2

Add DATABASE_URL to .env file and run test-e2e script to do the message test.

The test sends a job to a queue with a job name and payload and fetches the job afterwards to confirm the job created.
The job is found in pgboss schema under job table.

image

image

Copy link
Contributor

@dadiorchen dadiorchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! The pgboss did exactly what I wanted: use jsonb to store the message, so in this way, in the future, we can query the message by filter easily, this is important to us.

Comment on lines 6 to 18
it(
'message/',
async () => {
const response = await supertest(app).post('/message').send({jobName: 'add-tree-test', payload: {treeId: '0101010101'}});
expect(response.status).toBe(200); // eslint-disable-line
expect(response.body.job.name).toEqual('add-tree-test'); // eslint-disable-line
expect(response.body.job.data).toMatchObject({ // eslint-disable-line
treeId: '0101010101'
})
},
1000 * 30
)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dagmawig please test the receiving, that is to say, you should subscribe the message queue name: 'add-tree-test' and make sure the message that you sent is received by the client.

like this:

it('test', done => {
  const client = new pgboss.client();
  client.subscribe('add-tree-test', data => {
    expect(data).toMatchObject({message:'ssss'});
    done();
   });
   // do the post

}}

@dagmawig
Copy link
Collaborator Author

dagmawig commented Jul 6, 2024

In this fix instead of just sending job to queue, it also completes the job and confirms the job completed.

image

@dagmawig dagmawig marked this pull request as ready for review July 6, 2024 20:01
@dagmawig dagmawig requested a review from dadiorchen July 6, 2024 20:01
@dagmawig
Copy link
Collaborator Author

@dadiorchen I have replaced pg-boss with postgres listen-notify client system. For the e-2-e test I have created two separate pg clients and confirmed they both receive the notification of record insertion. We can add more functionalities in separate PRs later but I believe this will take care of the need for a proof of concept. Please review and let me know what you think.

__tests__/e2e/message.spec.js Outdated Show resolved Hide resolved
@dagmawig
Copy link
Collaborator Author

dagmawig commented Aug 6, 2024

Below is what the message table looks like. Based on the value under the name column, the queue schema function sends the message to the appropriate channel.
image

@dagmawig dagmawig merged commit 91e4d70 into Greenstand:main Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants