ews-api 0.1.0.a

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module EWS
4
+
5
+ describe Attachment do
6
+ before(:each) do
7
+ @parser = Parser.new
8
+ @attachment = @parser.parse_get_attachment response_to_doc(:get_attachment)
9
+ end
10
+
11
+ it "should have an attachment_id" do
12
+ @attachment.attachment_id.should == 'CCC'
13
+ end
14
+
15
+ it "id should be the same as the attachment id" do
16
+ @attachment.id.should == @attachment.attachment_id
17
+ end
18
+
19
+ it "should have a content_type" do
20
+ @attachment.content_type.should == 'message/rfc822'
21
+ end
22
+
23
+ it "item should be a Message" do
24
+ @attachment.item.should be_instance_of(Message)
25
+ @attachment.item.subject.should == 'I am subject. Hear me roar.'
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module EWS
4
+ describe Folder do
5
+ before(:each) do
6
+ @parser = Parser.new
7
+ end
8
+
9
+ context '#folders' do
10
+ it "should be indexed by display name" do
11
+ mock_response response(:find_folder)
12
+ folder = Folder.new
13
+ folder.folders['subfolder1'].should_not be_nil
14
+ folder.folders['subfolder2'].should_not be_nil
15
+ end
16
+ end
17
+
18
+ context '#each_message' do
19
+ it "should iterate through the messages" do
20
+ mock_response response(:find_item_all_properties)
21
+
22
+ message_count = 0
23
+ subjects = ['test', 'Regarding Brandon Stark', 'Re: Regarding Brandon Stark']
24
+ folder = Folder.new(:display_name => 'Inbox')
25
+
26
+ folder.each_message do |message|
27
+ message_count += 1
28
+ message.subject.should == subjects.shift
29
+ end
30
+
31
+ message_count.should == 3
32
+ end
33
+ end
34
+
35
+ context 'get' do
36
+ before(:each) do
37
+ @folder = @parser.parse_get_folder response_to_doc(:get_folder)
38
+ end
39
+
40
+ it "id should be the folder id id" do
41
+ @folder.id.should == 'AAA'
42
+ end
43
+
44
+ it "change ley should be the folder id change key" do
45
+ @folder.change_key.should == 'BBB'
46
+ end
47
+
48
+ it "should have a folder_id" do
49
+ @folder.folder_id.should == {:id => 'AAA', :change_key => 'BBB'}
50
+ end
51
+
52
+ it "should have a display name" do
53
+ @folder.display_name.should == 'Inbox'
54
+ end
55
+
56
+ it "name should be the same as display name" do
57
+ @folder.name.should == @folder.display_name
58
+ end
59
+
60
+ it "should have a total count" do
61
+ @folder.total_count.should == 43
62
+ end
63
+
64
+ it "should have a child folder count" do
65
+ @folder.child_folder_count.should == 2
66
+ end
67
+
68
+ it "should have a unread count" do
69
+ @folder.unread_count.should == 0
70
+ end
71
+ end
72
+
73
+ context 'find' do
74
+ before(:each) do
75
+ @folders = @parser.parse_find_folder response_to_doc(:find_folder)
76
+ end
77
+
78
+ it "should build an array of folders" do
79
+ @folders.size.should > 0
80
+ @folders.first.should be_instance_of(Folder)
81
+ end
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module EWS
4
+
5
+ describe Message do
6
+ before(:each) do
7
+ @parser = Parser.new
8
+ @message = @parser.parse_get_item response_to_doc(:get_item_all_properties)
9
+ end
10
+
11
+ it "#id should be the item_id id" do
12
+ @message.id.should == 'HRlZ'
13
+ end
14
+
15
+ it "#change_key should be the item_id change_key" do
16
+ @message.change_key.should == '0Tk4V'
17
+ end
18
+
19
+ it "should be able to move itself to the give folder id" do
20
+ id = 'xyz'
21
+ folder_id = '123'
22
+ Service.should_receive(:move_item!).with(folder_id, [id])
23
+
24
+ Message.new(:item_id => {:id => id}).move_to!(folder_id)
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe EWS::Model do
4
+ context 'with a method ending in ?' do
5
+ it "should return true when the attribute value is true" do
6
+ model = EWS::Model.new(:has_attachment => true)
7
+ model.should have_attachment
8
+ end
9
+
10
+ it "should return false when the attribute value is not true" do
11
+ model = EWS::Model.new(:has_attachment => false)
12
+ model.should_not have_attachment
13
+
14
+ model = EWS::Model.new(:has_attachment => nil)
15
+ model.should_not have_attachment
16
+
17
+ model = EWS::Model.new(:has_attachment => 'no')
18
+ model.should_not have_attachment
19
+ end
20
+ end
21
+
22
+ context 'with a method ending in =' do
23
+ it "should set the attribute's value" do
24
+ model = EWS::Model.new
25
+ model.subject = 'A Feast for Crows'
26
+
27
+ model.subject.should == 'A Feast for Crows'
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,119 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module EWS
4
+
5
+ describe Parser do
6
+ before(:each) do
7
+ @parser = Parser.new
8
+ end
9
+
10
+ context 'parsing find_item with the base_shape of "AllProperties"' do
11
+ before(:each) do
12
+ @items = @parser.parse_find_item response_to_doc(:find_item_all_properties)
13
+ @item = @items.first
14
+ end
15
+
16
+ it "should build an array of items" do
17
+ @items.size.should == 3
18
+ end
19
+
20
+ it "should set the item id" do
21
+ @item.item_id.should == {:id => 'BUEm5G5U', :change_key => 'LABU0Ut45'}
22
+ end
23
+
24
+ it "should set the message body to nil" do
25
+ @item.body.should be_nil
26
+ end
27
+
28
+ it "should set the attachments to nil because they are not in the response" do
29
+ @item.attachments.should be_nil
30
+ end
31
+
32
+ it "should set the header to nil because the internet message headers are not in the response" do
33
+ @item.header.should be_nil
34
+ end
35
+ end
36
+
37
+ context 'parsing get_item with all properites should build a message with' do
38
+ MESSAGE_BODY = "<html><body>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ullamcorper egestas accumsan. Nulla rhoncus porttitor dictum. Curabitur ac nulla a orci sollicitudin blandit at quis odio. Integer eleifend fringilla bibendum. Sed condimentum, lectus vitae suscipit sollicitudin, quam tortor faucibus nisl, ac tristique lectus justo in leo. Aliquam placerat arcu erat, vel lobortis dui. Nulla posuere sodales sapien eu interdum. Cras in pretium ante. Pellentesque ut velit est. Quisque nisl risus, molestie vel porta in, pellentesque a odio. Curabitur sit amet faucibus lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas et fermentum enim. Nulla ac dolor elit. Quisque eu dui sapien, ac tincidunt orci.</body></html>"
39
+
40
+ before(:each) do
41
+ @message = @parser.parse_get_item response_to_doc(:get_item_all_properties)
42
+ end
43
+
44
+ { :item_id => {:id => 'HRlZ', :change_key => '0Tk4V'},
45
+ :parent_folder_id => {:id => 'AQAUAAA', :change_key => 'AQAAAA=='},
46
+ :subject => 'A Clash of Kings',
47
+ :body => MESSAGE_BODY,
48
+ :body_type => 'HTML',
49
+ :has_attachments => true
50
+ }.each do |attr, value|
51
+
52
+ it attr do
53
+ @message.send(attr).should == value
54
+ end
55
+ end
56
+
57
+ it "attachments" do
58
+ @message.attachments.size.should == 1
59
+
60
+ attachment = @message.attachments.first
61
+ attachment.attachment_id.should == "UAHR"
62
+ attachment.name.should == "A Clash of Kings"
63
+ attachment.content_type.should == "message/rfc822"
64
+ end
65
+
66
+ it "header" do
67
+ @message.header.size.should == 7
68
+
69
+ @message.header['received'] = ['from example.com (0.0.0.0) by example.com (0.0.0.0) with SMTP Server id 0.0.0.0; Wed, 2 Dec 2009 10:38:47 -0600',
70
+ 'from example.com ([0.0.0.0]) by example.com with SMTP; 02 Dec 2009 10:38:47 -0600',
71
+ 'from example.com (0.0.0.0) by example.com (0.0.0.0) with SMTP Server id 0.0.0.0; Wed, 2 Dec 2009 10:38:47 -0600',
72
+ 'from localhost by example.com; 02 Dec 2009 10:38:47 -0600']
73
+
74
+ @message.header['subject'].should == ['A Clash of Kings']
75
+ @message.header['message-id'].should == ['<847mtq@example.com>']
76
+ @message.header['date'].should == ['Wed, 2 Dec 2009 10:38:47 -0600']
77
+ @message.header['mime-version'].should == ['1.0']
78
+ @message.header['content-type'].should == ['multipart/report']
79
+ @message.header['return-path'].should == ['<>']
80
+ end
81
+ end
82
+
83
+ context 'parsing get_item with no attachments' do
84
+ before(:each) do
85
+ @message = @parser.parse_get_item response_to_doc(:get_item_no_attachments)
86
+ end
87
+
88
+ it "should create an item with an empty array of attachments" do
89
+ @message.attachments.should == []
90
+ end
91
+ end
92
+
93
+ context 'parsing get_item with base_shape of "IdOnly"' do
94
+ before(:each) do
95
+ @message = @parser.parse_get_item response_to_doc(:get_item_id_only)
96
+ end
97
+
98
+ it "should set the item_id" do
99
+ @message.item_id[:id].should == 'AFTRNedwA'
100
+ @message.item_id[:change_key].should == 'FwAAA'
101
+ end
102
+ end
103
+
104
+ context 'parsing get_item with base_shape of "Default"' do
105
+ before(:each) do
106
+ @message = @parser.parse_get_item response_to_doc(:get_item_default)
107
+ end
108
+
109
+ it "should set the parent_folder_id to nil" do
110
+ @message.parent_folder_id be_nil
111
+ end
112
+
113
+ it "should set the header to nil when the internet message headers are not present" do
114
+ @message.header.should be_nil
115
+ end
116
+ end
117
+
118
+ end
119
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ EWS::Service.endpoint 'http://localhost/ews/exchange.aspx'
4
+
5
+ describe EWS::Service do
6
+ context '#get_item' do
7
+ it "should raise an error when the id is not found" do
8
+ mock_response response(:get_item_with_error)
9
+ lambda do
10
+ EWS::Service.get_item nil
11
+ end.should raise_error(EWS::ResponseError, 'Id must be non-empty.')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ <m:FindFolderResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
2
+ <m:ResponseMessages>
3
+ <m:FindFolderResponseMessage ResponseClass="Success">
4
+ <m:ResponseCode>NoError</m:ResponseCode>
5
+ <m:RootFolder TotalItemsInView="2" IncludesLastItemInRange="true">
6
+ <t:Folders>
7
+ <t:Folder>
8
+ <t:FolderId Id="1" ChangeKey="1"/>
9
+ <t:DisplayName>subfolder1</t:DisplayName>
10
+ <t:TotalCount>0</t:TotalCount>
11
+ <t:ChildFolderCount>0</t:ChildFolderCount>
12
+ <t:UnreadCount>0</t:UnreadCount>
13
+ </t:Folder>
14
+ <t:Folder>
15
+ <t:FolderId Id="2" ChangeKey="2"/>
16
+ <t:DisplayName>subfolder2</t:DisplayName>
17
+ <t:TotalCount>0</t:TotalCount>
18
+ <t:ChildFolderCount>0</t:ChildFolderCount>
19
+ <t:UnreadCount>0</t:UnreadCount>
20
+ </t:Folder>
21
+ </t:Folders>
22
+ </m:RootFolder>
23
+ </m:FindFolderResponseMessage>
24
+ </m:ResponseMessages>
25
+ </m:FindFolderResponse>
@@ -0,0 +1,20 @@
1
+ <m:FindItemResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
2
+ <m:ResponseMessages>
3
+ <m:ResponseCode>NoError</m:ResponseCode>
4
+ <m:RootFolder TotalItemsInView="3" IncludesLastItemInRange="true">
5
+ <m:FindItemResponseMessage ResponseClass="Success">
6
+ <t:Items>
7
+ <t:Message>
8
+ <t:ItemId Id="1" ChangeKey="1"/>
9
+ </t:Message>
10
+ <t:Message>
11
+ <t:ItemId Id="2" ChangeKey="2"/>
12
+ </t:Message>
13
+ <t:Message>
14
+ <t:ItemId Id="3" ChangeKey="3"/>
15
+ </t:Message>
16
+ </t:Items>
17
+ </m:RootFolder>
18
+ </m:FindItemResponseMessage>
19
+ </m:ResponseMessages>
20
+ </m:FindItemResponse>
@@ -0,0 +1,120 @@
1
+ <m:FindItemResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
2
+ <m:ResponseMessages>
3
+ <m:FindItemResponseMessage ResponseClass="Success">
4
+ <m:ResponseCode>NoError</m:ResponseCode>
5
+ <m:RootFolder TotalItemsInView="3" IncludesLastItemInRange="true">
6
+ <t:Items>
7
+ <t:Message>
8
+ <t:ItemId Id="BUEm5G5U" ChangeKey="LABU0Ut45"/>
9
+ <t:ParentFolderId Id="AQAUAH" ChangeKey="AQA"/>
10
+ <t:ItemClass>IPM.Note</t:ItemClass>
11
+ <t:Subject>test</t:Subject>
12
+ <t:Sensitivity>Normal</t:Sensitivity>
13
+ <t:DateTimeReceived>2009-12-11T16:40:44Z</t:DateTimeReceived>
14
+ <t:Size>754</t:Size>
15
+ <t:Importance>Normal</t:Importance>
16
+ <t:IsSubmitted>false</t:IsSubmitted>
17
+ <t:IsDraft>false</t:IsDraft>
18
+ <t:IsFromMe>false</t:IsFromMe>
19
+ <t:IsResend>false</t:IsResend>
20
+ <t:IsUnmodified>true</t:IsUnmodified>
21
+ <t:DateTimeSent>2009-12-11T16:39:44Z</t:DateTimeSent>
22
+ <t:DateTimeCreated>2009-12-11T16:40:44Z</t:DateTimeCreated>
23
+ <t:DisplayCc/>
24
+ <t:DisplayTo>'foo-bar-test@example.com'</t:DisplayTo>
25
+ <t:HasAttachments>false</t:HasAttachments>
26
+ <t:Culture>en-US</t:Culture>
27
+ <t:Sender>
28
+ <t:Mailbox>
29
+ <t:Name>Lannister, Jaime</t:Name>
30
+ </t:Mailbox>
31
+ </t:Sender>
32
+ <t:ConversationIndex>Acp6gIr/Ta2Ik/1+S+apI9ymV3kTuw==</t:ConversationIndex>
33
+ <t:ConversationTopic>test</t:ConversationTopic>
34
+ <t:From>
35
+ <t:Mailbox>
36
+ <t:Name>Stark, Eddard</t:Name>
37
+ </t:Mailbox>
38
+ </t:From>
39
+ <t:InternetMessageId>&lt;93C802589845@example.com&gt;</t:InternetMessageId>
40
+ <t:IsRead>true</t:IsRead>
41
+ </t:Message>
42
+ <t:Message>
43
+ <t:ItemId Id="4wpPi" ChangeKey="FwAAABYA"/>
44
+ <t:ParentFolderId Id="AQAU" ChangeKey="AQA"/>
45
+ <t:ItemClass>REPORT.IPM.Note.NDR</t:ItemClass>
46
+ <t:Subject>Regarding Brandon Stark</t:Subject>
47
+ <t:Sensitivity>Normal</t:Sensitivity>
48
+ <t:DateTimeReceived>2009-12-10T04:03:04Z</t:DateTimeReceived>
49
+ <t:Size>5492</t:Size>
50
+ <t:Importance>Normal</t:Importance>
51
+ <t:IsSubmitted>false</t:IsSubmitted>
52
+ <t:IsDraft>false</t:IsDraft>
53
+ <t:IsFromMe>false</t:IsFromMe>
54
+ <t:IsResend>false</t:IsResend>
55
+ <t:IsUnmodified>true</t:IsUnmodified>
56
+ <t:DateTimeSent>2009-12-10T04:03:04Z</t:DateTimeSent>
57
+ <t:DateTimeCreated>2009-12-10T04:03:04Z</t:DateTimeCreated>
58
+ <t:DisplayCc/>
59
+ <t:DisplayTo>tyrion@example.com</t:DisplayTo>
60
+ <t:HasAttachments>true</t:HasAttachments>
61
+ <t:Culture>en-US</t:Culture>
62
+ <t:Sender>
63
+ <t:Mailbox>
64
+ <t:Name>Tyrion Lannister</t:Name>
65
+ </t:Mailbox>
66
+ </t:Sender>
67
+ <t:IsReadReceiptRequested>false</t:IsReadReceiptRequested>
68
+ <t:IsDeliveryReceiptRequested>false</t:IsDeliveryReceiptRequested>
69
+ <t:ConversationIndex>Acp5TaxEDBVAU</t:ConversationIndex>
70
+ <t:ConversationTopic>Regarding Brandon Stark</t:ConversationTopic>
71
+ <t:From>
72
+ <t:Mailbox>
73
+ <t:Name>Tyrion Lannister</t:Name>
74
+ </t:Mailbox>
75
+ </t:From>
76
+ <t:InternetMessageId>&lt;871mi5@example.com&gt;</t:InternetMessageId>
77
+ <t:IsRead>true</t:IsRead>
78
+ </t:Message>
79
+ <t:Message>
80
+ <t:ItemId Id="AA==" ChangeKey="FwAA"/>
81
+ <t:ParentFolderId Id="XncAAAA" ChangeKey="AQAA"/>
82
+ <t:ItemClass>REPORT.IPM.Note.NDR</t:ItemClass>
83
+ <t:Subject>Re: Regarding Brandon Stark</t:Subject>
84
+ <t:Sensitivity>Normal</t:Sensitivity>
85
+ <t:DateTimeReceived>2009-12-08T04:04:13Z</t:DateTimeReceived>
86
+ <t:Size>5492</t:Size>
87
+ <t:Importance>Normal</t:Importance>
88
+ <t:IsSubmitted>false</t:IsSubmitted>
89
+ <t:IsDraft>false</t:IsDraft>
90
+ <t:IsFromMe>false</t:IsFromMe>
91
+ <t:IsResend>false</t:IsResend>
92
+ <t:IsUnmodified>true</t:IsUnmodified>
93
+ <t:DateTimeSent>2009-12-08T04:04:13Z</t:DateTimeSent>
94
+ <t:DateTimeCreated>2009-12-08T04:04:13Z</t:DateTimeCreated>
95
+ <t:DisplayCc/>
96
+ <t:DisplayTo>tyrion@example.com</t:DisplayTo>
97
+ <t:HasAttachments>true</t:HasAttachments>
98
+ <t:Culture>en-US</t:Culture>
99
+ <t:Sender>
100
+ <t:Mailbox>
101
+ <t:Name>Tyrion Lannister</t:Name>
102
+ </t:Mailbox>
103
+ </t:Sender>
104
+ <t:IsReadReceiptRequested>false</t:IsReadReceiptRequested>
105
+ <t:IsDeliveryReceiptRequested>false</t:IsDeliveryReceiptRequested>
106
+ <t:ConversationIndex>AcAAA7</t:ConversationIndex>
107
+ <t:ConversationTopic>Re: Regarding Braondon Stark</t:ConversationTopic>
108
+ <t:From>
109
+ <t:Mailbox>
110
+ <t:Name>Tyrion Lannister</t:Name>
111
+ </t:Mailbox>
112
+ </t:From>
113
+ <t:InternetMessageId>&lt;7@example.com&gt;</t:InternetMessageId>
114
+ <t:IsRead>true</t:IsRead>
115
+ </t:Message>
116
+ </t:Items>
117
+ </m:RootFolder>
118
+ </m:FindItemResponseMessage>
119
+ </m:ResponseMessages>
120
+ </m:FindItemResponse>