Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

hydro.js 1.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  1. const nock = require('nock')
  2. const Hydro = require('../../lib/hydro')
  3. describe('hydro', () => {
  4. let hydro, params
  5. beforeEach(() => {
  6. hydro = new Hydro({ secret: '123', endpoint: 'https://real-hydro.com' })
  7. nock(hydro.endpoint, {
  8. reqheaders: {
  9. Authorization: /^Hydro [\d\w]{64}$/,
  10. 'Content-Type': 'application/json',
  11. 'X-Hydro-App': 'docs-production'
  12. }
  13. })
  14. // Respond with a 200 and store the body we sent
  15. .post('/').reply(200, (_, body) => { params = body })
  16. })
  17. describe('#publish', () => {
  18. it('publishes a single event to Hydro', async () => {
  19. await hydro.publish('event-name', { pizza: true })
  20. expect(params).toEqual({
  21. events: [{
  22. schema: 'event-name',
  23. value: JSON.stringify({ pizza: true }),
  24. cluster: 'potomac'
  25. }]
  26. })
  27. })
  28. })
  29. describe('#publishMany', () => {
  30. it('publishes multiple events to Hydro', async () => {
  31. await hydro.publishMany([
  32. { schema: 'event-name', value: { pizza: true } },
  33. { schema: 'other-name', value: { salad: false } }
  34. ])
  35. expect(params).toEqual({
  36. events: [{
  37. schema: 'event-name',
  38. value: JSON.stringify({ pizza: true }),
  39. cluster: 'potomac'
  40. }, {
  41. schema: 'other-name',
  42. value: JSON.stringify({ salad: false }),
  43. cluster: 'potomac'
  44. }]
  45. })
  46. })
  47. })
  48. describe('#generatePayloadHmac', () => {
  49. it('returns a SHA256 HMAC string', () => {
  50. const body = JSON.stringify({ pizza: true })
  51. const hash = hydro.generatePayloadHmac(body)
  52. expect(hash).toEqual(expect.any(String))
  53. expect(hash).toHaveLength(64)
  54. })
  55. it('generates the same string for the same payload', () => {
  56. const body = JSON.stringify({ pizza: true })
  57. const one = hydro.generatePayloadHmac(body)
  58. const two = hydro.generatePayloadHmac(body)
  59. expect(one).toBe(two)
  60. })
  61. })
  62. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...