@@ -5,6 +5,16 @@ let gmail = new Gmail();
5
5
6
6
const testData = require ( "./testdata-parser.js" ) ;
7
7
8
+ function testXhrEventParsing ( jsonXhrData , eventName ) {
9
+ const api = new Gmail ( ) ;
10
+ const xhrData = JSON . parse ( jsonXhrData ) ;
11
+
12
+ const threads = api . tools . extract_from_graph ( xhrData , api . check . data . is_thread ) ;
13
+ const actionType = api . tools . check_event_type ( threads [ 0 ] ) ;
14
+
15
+ assert . equal ( eventName , actionType ) ;
16
+ } ;
17
+
8
18
describe ( "Monkeypatching" , ( ) => {
9
19
it ( "patching functions works" , ( ) => {
10
20
var ns = { } ;
@@ -51,36 +61,53 @@ describe("Monkeypatching", () => {
51
61
describe ( "Test tools for parsing new gmail body_params" , ( ) => {
52
62
const gmail = new Gmail ( ) ;
53
63
const data = JSON . parse ( testData . new_gmail_archive_action_body_params ) ;
64
+ const threads = gmail . tools . extract_from_graph ( data , gmail . check . data . is_thread ) ;
65
+ const threadData = threads . map ( thread => gmail . tools . get_thread_data ( thread ) ) [ 0 ] ;
54
66
55
67
it ( "get thread id" , ( ) => {
56
- const thread = gmail . tools . get_thread_id ( data ) ;
68
+ const thread = gmail . tools . get_thread_id ( threads [ 0 ] ) ;
57
69
58
- assert . equal ( thread , 'thread-f:1600724307680265309 ' ) ;
70
+ assert . equal ( thread , 'thread-f:1603171109786600032 ' ) ;
59
71
} ) ;
72
+
60
73
it ( "get thread data" , ( ) => {
61
- const mockThreadData = data [ 2 ] [ 7 ] ;
62
- const threadData = gmail . tools . get_thread_data ( data ) ;
74
+ const mockThreadData = threads [ 0 ] [ 2 ] [ 7 ] ;
75
+ const threadData = gmail . tools . get_thread_data ( threads [ 0 ] ) ;
76
+ console . log ( threadData ) ;
63
77
64
78
assert . deepEqual ( threadData , mockThreadData ) ;
65
79
} ) ;
80
+
66
81
it ( "get messages ids" , ( ) => {
67
- const mockMessageIds = [ 'msg-f:1600724307680265309' , 'msg-f:1600724938213937205' , 'msg-f:1600725174437456906' , 'msg-f:1600725319255992336' , 'msg-f:1600725448529658711' ] ;
68
- const threadData = gmail . tools . get_thread_data ( data ) ;
82
+ const mockMessageIds = [ 'msg-f:1603171109786600032' , 'msg-f:1603245801543734539' , 'msg-f:1603245862071354412' , 'msg-f:1603246018478443087' , 'msg-f:1603256094012730022' , 'msg-f:1603256564311088576' , 'msg-f:1603256665279246114' , 'msg-f:1603256682384715664' , 'msg-f:1603376719891477511' , 'msg-f:1603376909485932601' , 'msg-f:1603376994923202634' , 'msg-f:1603380395240179639' ] ;
69
83
const messagesIds = gmail . tools . get_message_ids ( threadData ) ;
70
84
71
- assert . equal ( messagesIds . length , 5 ) ;
85
+ assert . equal ( messagesIds . length , 12 ) ;
72
86
assert . deepEqual ( messagesIds , mockMessageIds ) ;
73
87
} ) ;
74
- it ( "get action type" , ( ) => {
75
- const threadData = gmail . tools . get_thread_data ( data ) ;
76
- const action = gmail . tools . get_action_type ( threadData ) ;
77
88
78
- assert . equal ( action , "^a" ) ;
89
+ it ( "parses archived messages" , ( ) => {
90
+ const xhrData = testData . new_gmail_archive_action_body_params ;
91
+ testXhrEventParsing ( xhrData , "archive" ) ;
92
+ } ) ;
93
+
94
+ it ( "parses deleted messages" , ( ) => {
95
+ const xhrData = testData . new_gmail_delete_action_body_params ;
96
+ testXhrEventParsing ( xhrData , "delete" ) ;
97
+ } ) ;
98
+
99
+ it ( "parses read messages" , ( ) => {
100
+ const xhrData = testData . new_gmail_read_action_body_params ;
101
+ testXhrEventParsing ( xhrData , "read" ) ;
102
+ } ) ;
103
+
104
+ it ( "parses unread messages" , ( ) => {
105
+ const xhrData = testData . new_gmail_unread_action_body_params ;
106
+ testXhrEventParsing ( xhrData , "unread" ) ;
79
107
} ) ;
80
- it ( "is action type isset in thread object" , ( ) => {
81
- const threadData = gmail . tools . get_thread_data ( data ) ;
82
- const issetAction = gmail . check . data . is_action ( threadData ) ;
83
108
84
- assert . equal ( issetAction , true ) ;
109
+ it ( "parses open_email messages" , ( ) => {
110
+ const xhrData = testData . new_gmail_open_email_action_body_params ;
111
+ testXhrEventParsing ( xhrData , "open_email" ) ;
85
112
} ) ;
86
113
} ) ;
0 commit comments