1- import * as requests from '../src/model/requests/requests' ;
21import uuidv4 from 'uuid/v4' ;
3- import * as models from '../src/model/model' ;
42import 'mocha' ;
53import { expect } from 'chai' ;
64import { suiteBase } from "./suite-base" ;
5+ import {
6+ CalendarAsAlternateRequest ,
7+ CalendarAsFileRequest ,
8+ CalendarConvertRequest ,
9+ CalendarDto ,
10+ CalendarFromFileRequest ,
11+ CalendarSaveRequest ,
12+ DailyRecurrencePatternDto ,
13+ DownloadFileRequest ,
14+ EmailDto ,
15+ EmailSaveRequest ,
16+ MailAddress ,
17+ ObjectExistsRequest ,
18+ StorageFileLocation
19+ } from "../src/model" ;
720
821describe ( 'Calendar tests' , function ( ) {
922 let td = suiteBase ( this ) ;
1023
11- /*
12- * HierarchicalObject serialization and deserialization test.
13- * This test checks that BaseObject.Type field filled automatically by SDK
14- * and properly used in serialization and deserialization
15- */
16- it ( 'HierarchicalObject #pipeline' , async function ( ) {
17- const calendarFile = await td . createCalendar ( ) ;
18- const calendar = await td . api ( ) . getCalendar (
19- new requests . GetCalendarRequest ( calendarFile , td . folder ( ) , td . storage ( ) ) ) ;
20- expect ( calendar . body . name ) . to . be . equal ( 'CALENDAR' ) ;
21- const filtered = calendar . body . internalProperties . filter ( item => item . type == 'PrimitiveObject' ) ;
22- expect ( filtered . length ) . to . be . at . least ( 3 ) ;
23- const primitive = filtered [ 0 ] as models . PrimitiveObject ;
24- expect ( primitive . value ) . to . not . be . undefined ;
25- } ) ;
26-
27- /**
28- * Buffer support test
29- */
30- it ( 'FileTest #pipeline' , async function ( ) {
31- let calendarFile = await td . createCalendar ( ) ;
32- let path = td . folder ( ) + '/' + calendarFile ;
33- const downloaded = await td . api ( ) . downloadFile ( new requests . DownloadFileRequest ( path , td . storage ( ) ) ) ;
34- const calendarRaw = downloaded . body . toString ( ) ;
35- expect ( calendarRaw ) . to . contain ( 'Organizer' ) ;
36- calendarFile = uuidv4 ( ) + '.ics' ;
37- path = td . folder ( ) + '/' + calendarFile ;
38- await td . api ( ) . uploadFile ( new requests . UploadFileRequest ( path , downloaded . body , td . storage ( ) ) ) ;
39- const exist = await td . api ( ) . objectExists ( new requests . ObjectExistsRequest ( path , td . storage ( ) ) ) ;
40- expect ( exist . body . exists ) . to . be . ok ;
41- const calendar = await td . api ( ) . getCalendar (
42- new requests . GetCalendarRequest ( calendarFile , td . folder ( ) , td . storage ( ) ) ) ;
43- const location = calendar . body . internalProperties
44- . find ( item => item . type == 'PrimitiveObject' && item . name == 'LOCATION' ) as models . PrimitiveObject ;
45- expect ( location . value ) . to . equal ( 'location' ) ;
46- } ) ;
47-
4824 it ( 'Check calendar converter #pipeline' , async function ( ) {
49- const location = 'Some location' ;
5025 //Create DTO with specified location:
5126 let calendarDto = getCalendarDto ( ) ;
5227 //We can convert this DTO to a MAPI or ICS file:
53- let mapi = await td . api ( ) . convertCalendarModelToFile ( new requests . ConvertCalendarModelToFileRequest (
54- 'Msg' , calendarDto ) ) ;
28+ let mapi = await td . api ( ) . calendar . asFile ( new CalendarAsFileRequest ( 'Msg' , calendarDto ) ) ;
5529 //File content is available at mapi.body as a Buffer object
5630 //Let's convert this buffer to an ICS file:
57- let ics = await td . api ( ) . convertCalendar ( new requests . ConvertCalendarRequest (
58- 'Ics' , mapi . body ) ) ;
31+ let ics = await td . api ( ) . calendar . convert ( new CalendarConvertRequest ( 'Ics' , mapi ) ) ;
5932 //ICS is a text format. We can convert the buffer to a string and check that it
6033 //contains specified location as a substring:
61- let icsString = ics . body . toString ( ) ;
62- expect ( icsString ) . to . include ( location ) ;
34+ let icsString = ics . toString ( ) ;
35+ expect ( icsString ) . to . include ( calendarDto . location ) ;
6336 //We can also convert a file buffer back to a CalendarDto
64- let dto = await td . api ( ) . getCalendarFileAsModel ( new requests . GetCalendarFileAsModelRequest ( ics . body ) ) ;
65- expect ( dto . body . location ) . to . be . equal ( location ) ;
66- } ) ;
67-
68- /**
69- * Test Date serialization and deserialization.
70- * Checks that SDK and Backend do not change Date during processing.
71- * In most cases developer should carefully serialize and deserialize Date
72- */
73- it ( 'Date #pipeline' , async function ( ) {
74- const startDate = td . getDate ( undefined , 24 ) ;
75- startDate . setMilliseconds ( 0 ) ;
76- const calendarFile = await td . createCalendar ( startDate ) ;
77- const calendar = await td . api ( ) . getCalendar (
78- new requests . GetCalendarRequest ( calendarFile , td . folder ( ) , td . storage ( ) ) ) ;
79- const startDateProperty = calendar . body . internalProperties . find (
80- item => item . name == 'STARTDATE' ) as models . PrimitiveObject ;
81- const factStartDate = new Date ( startDateProperty . value ) ;
82- expect ( factStartDate . getTime ( ) ) . to . equal ( startDate . getTime ( ) ) ;
37+ let dto = await td . api ( ) . calendar . fromFile ( new CalendarFromFileRequest ( ics ) ) ;
38+ expect ( dto . location ) . to . be . equal ( calendarDto . location ) ;
8339 } ) ;
8440
8541 it ( 'Create calendar email #pipeline' , async function ( ) {
8642 const calendar = getCalendarDto ( ) ;
87- const folderLocation = new models . StorageFolderLocation ( td . storage ( ) , td . folder ( ) ) ;
8843 const calendarFile = uuidv4 ( ) + '.ics' ;
89- await td . api ( ) . saveCalendarModel (
90- new requests . SaveCalendarModelRequest (
91- calendarFile ,
92- new models . StorageModelRqOfCalendarDto (
93- calendar ,
94- folderLocation ) ) ) ;
95- const exists = await td . api ( ) . objectExists (
96- new requests . ObjectExistsRequest ( td . folder ( ) + '/' + calendarFile , td . storage ( ) ) ) ;
97- expect ( exists . body . exists ) . to . be . ok ;
44+ await td . api ( ) . calendar . save ( new CalendarSaveRequest (
45+ new StorageFileLocation ( td . storage ( ) , td . folder ( ) , calendarFile ) , calendar ) ) ;
46+ const exists = await td . api ( ) . cloudStorage . storage . objectExists (
47+ new ObjectExistsRequest ( td . folder ( ) + '/' + calendarFile , td . storage ( ) ) ) ;
48+ expect ( exists . exists ) . to . be . ok ;
9849
99- const alternate = await td . api ( ) . convertCalendarModelToAlternate (
100- new requests . ConvertCalendarModelToAlternateRequest (
101- new models . CalendarDtoAlternateRq ( calendar , 'Create' ) ) ) ;
50+ const alternate = await td . api ( ) . calendar . asAlternate ( new CalendarAsAlternateRequest ( calendar , 'Create' ) ) ;
10251
103- const email = new models . EmailDto ( ) ;
104- email . alternateViews = [ alternate . body ] ;
105- email . from = new models . MailAddress ( 'From address' , 'cloud.em@yandex.ru' ) ;
106- email . to = [ new models . MailAddress ( 'To address' , 'cloud.em@yandex.ru' ) ] ;
52+ const email = new EmailDto ( ) ;
53+ email . alternateViews = [ alternate ] ;
54+ email . from = new MailAddress ( 'From address' , 'cloud.em@yandex.ru' ) ;
55+ email . to = [ new MailAddress ( 'To address' , 'cloud.em@yandex.ru' ) ] ;
10756 email . subject = 'Some subject' ;
10857 email . body = 'Some body' ;
10958
11059 const emailFile = uuidv4 ( ) + '.eml' ;
111- await td . api ( ) . saveEmailModel (
112- new requests . SaveEmailModelRequest (
113- 'Eml' , emailFile , new models . StorageModelRqOfEmailDto (
114- email , folderLocation ) ) ) ;
60+ await td . api ( ) . email . save (
61+ new EmailSaveRequest ( new StorageFileLocation ( td . storage ( ) , td . folder ( ) , emailFile ) , email , 'Eml' ) ) ;
11562
116- const downloaded = await td . api ( ) . downloadFile (
117- new requests . DownloadFileRequest (
118- td . folder ( ) + '/' + emailFile , td . storage ( ) ) ) ;
119- const downloadedRaw = downloaded . body . toString ( ) ;
63+ const downloaded = await td . api ( ) . cloudStorage . file . downloadFile (
64+ new DownloadFileRequest ( td . folder ( ) + '/' + emailFile , td . storage ( ) ) ) ;
65+ const downloadedRaw = downloaded . toString ( ) ;
12066 expect ( downloadedRaw ) . to . contain ( 'cloud.em@yandex.ru' ) ;
12167 } ) ;
12268
12369 it ( 'Convert model to MapiModel #pipeline' , async ( ) => {
12470 const calendarDto = getCalendarDto ( ) ;
125- const mapiCalendarDto = await td . api ( ) . convertCalendarModelToMapiModel (
126- new requests . ConvertCalendarModelToMapiModelRequest ( calendarDto ) ) ;
127- expect ( calendarDto . location ) . to . be . eq ( mapiCalendarDto . body . location ) ;
71+ const mapiCalendarDto = await td . api ( ) . calendar . asMapi ( calendarDto ) ;
72+ expect ( calendarDto . location ) . to . be . eq ( mapiCalendarDto . location ) ;
12873 expect ( 'MapiCalendarDailyRecurrencePatternDto' ) . to . be . eq (
129- mapiCalendarDto . body . recurrence . recurrencePattern . discriminator ) ;
74+ mapiCalendarDto . recurrence . recurrencePattern . discriminator ) ;
13075 } ) ;
13176
132- function getCalendarDto ( ) : models . CalendarDto {
133- let calendar = new models . CalendarDto ( ) ;
77+ function getCalendarDto ( ) : CalendarDto {
78+ let calendar = new CalendarDto ( ) ;
13479 calendar . attendees = [
135- new models . MailAddress ( 'Attendee Name' , 'attendee@am.ru' , 'Accepted' )
80+ new MailAddress ( 'Attendee Name' , 'attendee@am.ru' , 'Accepted' )
13681 ] ;
13782 calendar . description = 'Some description' ;
13883 calendar . summary = 'Some summary' ;
139- calendar . organizer = new models . MailAddress ( 'Organizer Name' , 'organizer@am.ru' ) ;
84+ calendar . organizer = new MailAddress ( 'Organizer Name' , 'organizer@am.ru' ) ;
14085 calendar . startDate = td . getDate ( undefined , 1 ) ;
14186 calendar . endDate = td . getDate ( calendar . startDate , 1 ) ;
14287 calendar . location = 'Some location' ;
143- calendar . recurrence = new models . DailyRecurrencePatternDto ( undefined , 10 , undefined , "Monday" ) ;
88+ calendar . recurrence = new DailyRecurrencePatternDto ( undefined , 10 , undefined , "Monday" ) ;
14489 return calendar ;
14590 }
14691} ) ;
0 commit comments