-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkafka_tests.js
More file actions
108 lines (93 loc) · 3.22 KB
/
kafka_tests.js
File metadata and controls
108 lines (93 loc) · 3.22 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const { expect } = require('chai');
// Simulated Kafka functions (replace with real imports as needed)
const {
producePostEvent,
produceLikeEvent,
produceCommentEvent,
consumePostEvent,
consumeLikeEvent,
consumeCommentEvent
} = require('../server/kafka_utils'); // Adjust the path based on your project structure
describe('Kafka Streaming Module', function () {
describe('producePostEvent(postData)', function () {
it('should return { success: true } for valid post data', async function () {
const postData = {
username: 'shreya',
source_site: 'g01',
post_uuid_within_site: 'post123',
post_text: 'hello from kafka!',
content_type: 'text/plain',
attach: null
};
const result = await producePostEvent(postData);
expect(result).to.be.an('object');
expect(result).to.have.property('success', true);
});
});
describe('produceLikeEvent(likeData)', function () {
it('should return { success: true } for valid like data', async function () {
const likeData = {
username: 'shreya',
post_uuid_within_site: 'post456'
};
const result = await produceLikeEvent(likeData);
expect(result).to.be.an('object');
expect(result).to.have.property('success', true);
});
});
describe('produceCommentEvent(commentData)', function () {
it('should return { success: true } for valid comment data', async function () {
const commentData = {
username: 'shreya',
commentId: 'comment321',
post_uuid_within_site: 'post111',
text: 'Nice post!'
};
const result = await produceCommentEvent(commentData);
expect(result).to.be.an('object');
expect(result).to.have.property('success', true);
});
});
describe('consumePostEvent(message)', function () {
it('should return { success: true } for valid post message', async function () {
const message = {
value: Buffer.from(JSON.stringify({
username: 'shreya',
source_site: 'g01',
post_uuid_within_site: 'post789',
post_text: 'Kafka testing!',
content_type: 'text/plain',
attach: null
}))
};
const result = await consumePostEvent(message);
expect(result).to.have.property('success', true);
});
});
describe('consumeLikeEvent(message)', function () {
it('should return { success: true } for valid like message', async function () {
const message = {
value: Buffer.from(JSON.stringify({
username: 'shreya',
post_uuid_within_site: 'post987'
}))
};
const result = await consumeLikeEvent(message);
expect(result).to.have.property('success', true);
});
});
describe('consumeCommentEvent(message)', function () {
it('should return { success: true } for valid comment message', async function () {
const message = {
value: Buffer.from(JSON.stringify({
username: 'shreya',
commentId: 'comment999',
post_uuid_within_site: 'post222',
text: 'Great post'
}))
};
const result = await consumeCommentEvent(message);
expect(result).to.have.property('success', true);
});
});
});