Skip to content

Commit 0771989

Browse files
committed
Added tests for MAPI message dto
1 parent a0da428 commit 0771989

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

test/calendar-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'mocha';
55
import {expect} from 'chai';
66
import {suiteBase} from "./suite-base";
77

8-
describe('Calendar tests', function() {
8+
describe('Calendar tests', function () {
99
let td = suiteBase(this);
1010

1111
/*

test/mapi-message-test.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import * as requests from '../src/model/requests/requests';
2+
import * as models from '../src/model/model';
3+
import 'mocha';
4+
import {expect} from 'chai';
5+
import {suiteBase} from "./suite-base";
6+
import uuidv4 from "uuid/v4";
7+
8+
9+
describe('MAPI contact tests', function () {
10+
let td = suiteBase(this);
11+
12+
it('Convert MAPI model to EmailDto #pipeline', async () => {
13+
const mapiMessageDto = getMapiMessageDto();
14+
const emailDto = await td.api().convertMapiMessageModelToEmailModel(
15+
new requests.ConvertMapiMessageModelToEmailModelRequest(mapiMessageDto));
16+
expect(mapiMessageDto.subject).to.be.eq(emailDto.body.subject);
17+
expect(mapiMessageDto.body).to.be.eq(emailDto.body.body);
18+
});
19+
20+
it('Convert MAPI model to file #pipeline', async () => {
21+
const mapiMessageDto = getMapiMessageDto();
22+
const emlFile = await td.api().convertMapiMessageModelToFile(
23+
new requests.ConvertMapiMessageModelToFileRequest('Eml', mapiMessageDto));
24+
const emlString = emlFile.body.toString();
25+
expect(emlString).to.contain(mapiMessageDto.subject);
26+
const mapiMessageDtoConverted = await td.api().getEmailFileAsMapiModel(
27+
new requests.GetEmailFileAsMapiModelRequest('Eml', emlFile.body));
28+
expect(mapiMessageDto.subject).to.be.eq(mapiMessageDtoConverted.body.subject);
29+
//Subject is also available as MapiPropertyDto:
30+
const subjectProperty = mapiMessageDtoConverted.body.properties
31+
//There are different Property descriptors supported.
32+
//Some properties are known to the service:
33+
.filter(i => i.descriptor.discriminator == 'MapiKnownPropertyDescriptor')
34+
//So we can find them by name:
35+
.find(i => (i.descriptor as models.MapiKnownPropertyDescriptor).name == 'TagSubject');
36+
//Subject is a string, so it is stored in MapiStringPropertyDto:
37+
const subjectString = (subjectProperty as models.MapiStringPropertyDto).value;
38+
expect(mapiMessageDto.subject).to.be.eq(subjectString);
39+
});
40+
41+
it('Mapi message storage test #pipeline', async () => {
42+
const mapiMessageDto = getMapiMessageDto();
43+
const fileName = uuidv4() + '.msg';
44+
await td.api().saveMapiMessageModel(
45+
new requests.SaveMapiMessageModelRequest('Msg', fileName,
46+
new models.StorageModelRqOfMapiMessageDto(mapiMessageDto, td.getStorageFolderLocation())));
47+
const mapiMessageFromStorage = await td.api().getMapiMessageModel(
48+
new requests.GetMapiMessageModelRequest('Msg', fileName, td.folder(), td.storage()));
49+
expect(mapiMessageDto.subject).to.be.eq(mapiMessageFromStorage.body.subject);
50+
});
51+
52+
function getMapiMessageDto(): models.MapiMessageDto {
53+
const mapiMessageDto = new models.MapiMessageDto();
54+
mapiMessageDto.clientSubmitTime = td.getDate();
55+
mapiMessageDto.senderAddressType = "SMTP";
56+
mapiMessageDto.senderEmailAddress = "from@aspose.com";
57+
mapiMessageDto.senderSmtpAddress = "from@aspose.com";
58+
mapiMessageDto.messageFormat = "Ascii";
59+
mapiMessageDto.senderName = "From Address";
60+
mapiMessageDto.messageBody = "Some body";
61+
mapiMessageDto.displayTo = "To Address";
62+
mapiMessageDto.deliveryTime = td.getDate();
63+
mapiMessageDto.normalizedSubject = "Some subject";
64+
mapiMessageDto.flags = ["MsgFlagRead", "MsgFlagUnsent", "MsgFlagHasAttach"];
65+
const recipientDto = new models.MapiRecipientDto();
66+
recipientDto.addressType = "SMTP";
67+
recipientDto.displayName = "To address";
68+
recipientDto.emailAddress = "to@aspose.com";
69+
recipientDto.recipientType = "MapiTo";
70+
mapiMessageDto.recipients = [recipientDto];
71+
const attachment = new models.MapiAttachmentDto();
72+
attachment.dataBase64 = Buffer.from("Some file text").toString('base64');
73+
attachment.name = "some-file.txt";
74+
mapiMessageDto.attachments = [attachment];
75+
mapiMessageDto.subjectPrefix = "Re: ";
76+
mapiMessageDto.messageClass = "IPM.Note";
77+
mapiMessageDto.body = "Some body";
78+
mapiMessageDto.subject = "Re: Some subject";
79+
mapiMessageDto.bodyType = "PlainText";
80+
return mapiMessageDto;
81+
}
82+
});

0 commit comments

Comments
 (0)