Skip to content
Browse files

first spam detection test

  • Loading branch information...
1 parent 6cec1f1 commit b6d980ab618963aed63dc22f73837ac3497bf533 @makeusabrew committed Nov 23, 2011
Showing with 42 additions and 0 deletions.
  1. +42 −0 tests/server/spec/StreamProcessorSpec.js
View
42 tests/server/spec/StreamProcessorSpec.js
@@ -1,3 +1,4 @@
+require('colors');
var srcDir = __dirname+'/../../..';
var StreamProcessor = require(srcDir+'/app/workers/stream_processor');
@@ -15,4 +16,45 @@ describe('StreamConsumer', function() {
new Error("parse error of: Invalid JSON")
);
});
+
+ it('should emit an eror when processing JSON without any text', function() {
+ expect(function() {
+ processor.process('{"valid":"json"}');
+ }).toThrow(
+ new Error("discarding message with bad format - assuming delete or rate limit info".bold)
+ );
+ });
+
+ it('should emit an error when encountering a swear word in the tweet text', function() {
+ expect(function() {
+ processor.process('{"text":"I don\'t give a fuck", "user":{"screen_name":"Foo"}}');
+ }).toThrow(
+ new Error("PROFANITY FILTER:".red+" [Foo: I don't give a fuck]")
+ );
+ });
+
+ it('should emit an error a user with no followers shares a link', function() {
+ var tweet = {
+ "text": "This is a link http://foo.com",
+ "user": {
+ "screen_name": "Foo",
+ "followers_count": 0,
+ },
+ "entities": {
+ "urls": [
+ {
+ "url" : "http://foo.com"
+ }
+ ]
+ }
+ };
+
+ tweet = JSON.stringify(tweet);
+
+ expect(function() {
+ processor.process(tweet);
+ }).toThrow(
+ new Error("SPAM FILTER:".yellow+" excessive link Vs follower count (1 Vs 0): Foo: This is a link http://foo.com")
+ );
+ });
});

0 comments on commit b6d980a

Please sign in to comment.
Something went wrong with that request. Please try again.