|
| 1 | +/* |
| 2 | + * -------------------------------------------------------------------------------- |
| 3 | + * <copyright company="Aspose" file="recurring_info_test.go"> |
| 4 | + * Copyright (c) 2021 Aspose.Tasks Cloud |
| 5 | + * </copyright> |
| 6 | + * <summary> |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all |
| 15 | + * copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + * </summary> |
| 25 | + * -------------------------------------------------------------------------------- |
| 26 | + */ |
| 27 | + |
| 28 | +// Example of how to work with recurring info. |
| 29 | +package api_test |
| 30 | + |
| 31 | +import ( |
| 32 | + "github.com/antihax/optional" |
| 33 | + "github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/models" |
| 34 | + "github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/requests" |
| 35 | + "github.com/stretchr/testify/assert" |
| 36 | + "testing" |
| 37 | +) |
| 38 | + |
| 39 | +// Test for get task recurring info. |
| 40 | +func Test_RecurringInfo_GetTaskRecurringInfo(t *testing.T) { |
| 41 | + localFileName := "sample.mpp" |
| 42 | + remoteFileName := CreateRandomGuid() + localFileName |
| 43 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 44 | + |
| 45 | + result, _, err := client.TasksApi.GetTaskRecurringInfo(ctx, &requests.GetTaskRecurringInfoOpts{ |
| 46 | + TaskUid: 6, |
| 47 | + Name: remoteFileName, |
| 48 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 49 | + }) |
| 50 | + if err != nil { |
| 51 | + t.Error(err) |
| 52 | + } |
| 53 | + assert.Equal(t, int32(200), result.Code) |
| 54 | + assert.Equal(t, int32(2), result.RecurringInfo.Occurrences) |
| 55 | + assert.Equal(t, models.MONTHLY_RecurrencePattern, *result.RecurringInfo.RecurrencePattern) |
| 56 | + assert.True(t, result.RecurringInfo.UseEndDate) |
| 57 | + assert.False(t, result.RecurringInfo.MonthlyUseOrdinalDay) |
| 58 | + assert.Equal(t, int32(1), result.RecurringInfo.MonthlyDay) |
| 59 | + assert.Equal(t, models.NONE_WeekDayType, *result.RecurringInfo.WeeklyDays) |
| 60 | + assert.Equal(t, models.SECOND_OrdinalNumber, *result.RecurringInfo.YearlyOrdinalNumber) |
| 61 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 62 | +} |
| 63 | + |
| 64 | +// Test for put task recurring info. |
| 65 | +func Test_RecurringInfo_PutTaskRecurringInfo(t *testing.T) { |
| 66 | + localFileName := "sample.mpp" |
| 67 | + remoteFileName := CreateRandomGuid() + localFileName |
| 68 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 69 | + |
| 70 | + getOpts := &requests.GetTaskRecurringInfoOpts{ |
| 71 | + TaskUid: 6, |
| 72 | + Name: remoteFileName, |
| 73 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 74 | + } |
| 75 | + getResult, _, err := client.TasksApi.GetTaskRecurringInfo(ctx, getOpts) |
| 76 | + if err != nil { |
| 77 | + t.Error(err) |
| 78 | + } |
| 79 | + assert.Equal(t, int32(200), getResult.Code) |
| 80 | + assert.NotNil(t, getResult.RecurringInfo) |
| 81 | + |
| 82 | + getResult.RecurringInfo.Occurrences = 10 |
| 83 | + putResult, _, err := client.TasksApi.PutTaskRecurringInfo(ctx, &requests.PutTaskRecurringInfoOpts{ |
| 84 | + TaskUid: 6, |
| 85 | + RecurringInfo: *getResult.RecurringInfo, |
| 86 | + Name: remoteFileName, |
| 87 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 88 | + }) |
| 89 | + if err != nil { |
| 90 | + t.Error(err) |
| 91 | + } |
| 92 | + assert.Equal(t, int32(200), putResult.Code) |
| 93 | + |
| 94 | + getResult, _, err = client.TasksApi.GetTaskRecurringInfo(ctx, getOpts) |
| 95 | + assert.Equal(t, int32(200), getResult.Code) |
| 96 | + assert.Equal(t, int32(10), getResult.RecurringInfo.Occurrences) |
| 97 | + assert.Equal(t, models.MONTHLY_RecurrencePattern, *getResult.RecurringInfo.RecurrencePattern) |
| 98 | + assert.True(t, getResult.RecurringInfo.UseEndDate) |
| 99 | + assert.False(t, getResult.RecurringInfo.MonthlyUseOrdinalDay) |
| 100 | + assert.Equal(t, int32(1), getResult.RecurringInfo.MonthlyDay) |
| 101 | + assert.Equal(t, models.NONE_WeekDayType, *getResult.RecurringInfo.WeeklyDays) |
| 102 | + assert.Equal(t, models.SECOND_OrdinalNumber, *getResult.RecurringInfo.YearlyOrdinalNumber) |
| 103 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 104 | +} |
| 105 | + |
| 106 | +// Test for post task recurring info. |
| 107 | +func Test_RecurringInfo_PostTaskRecurringInfo(t *testing.T) { |
| 108 | + localFileName := "sample.mpp" |
| 109 | + remoteFileName := CreateRandomGuid() + localFileName |
| 110 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 111 | + |
| 112 | + newRecurrencePattern := models.WEEKLY_RecurrencePattern |
| 113 | + newWeeklyDays := models.THURSDAY_WeekDayType |
| 114 | + newMonthlyOrdinalNumber := models.FIRST_OrdinalNumber |
| 115 | + newMonthlyOrdinalDay := models.MONDAY_DayOfWeek |
| 116 | + newYearlyOrdinalNumber := models.FIRST_OrdinalNumber |
| 117 | + newYearlyOrdinalDay := models.MONDAY_DayOfWeek |
| 118 | + newYearlyOrdinalMonth := models.DECEMBER_Month |
| 119 | + recurringInfo := models.RecurringInfo{ |
| 120 | + RecurrencePattern: &newRecurrencePattern, |
| 121 | + WeeklyDays: &newWeeklyDays, |
| 122 | + MonthlyOrdinalNumber: &newMonthlyOrdinalNumber, |
| 123 | + MonthlyOrdinalDay: &newMonthlyOrdinalDay, |
| 124 | + YearlyOrdinalNumber: &newYearlyOrdinalNumber, |
| 125 | + YearlyOrdinalDay: &newYearlyOrdinalDay, |
| 126 | + YearlyOrdinalMonth: &newYearlyOrdinalMonth, |
| 127 | + Occurrences: 4, |
| 128 | + WeeklyRepetitions: 3, |
| 129 | + StartDate: CreateTime(2018, 1, 1, 8, 0, 0), |
| 130 | + EndDate: CreateTime(2018, 12, 31, 0, 0, 0), |
| 131 | + UseEndDate: true, |
| 132 | + } |
| 133 | + postResult, _, err := client.TasksApi.PostTaskRecurringInfo(ctx, &requests.PostTaskRecurringInfoOpts{ |
| 134 | + ParentTaskUid: 0, |
| 135 | + TaskName: "New recurring task", |
| 136 | + CalendarName: "Standard", |
| 137 | + RecurringInfo: recurringInfo, |
| 138 | + Name: remoteFileName, |
| 139 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 140 | + }) |
| 141 | + if err != nil { |
| 142 | + t.Error(err) |
| 143 | + } |
| 144 | + assert.Equal(t, int32(201), postResult.Code) |
| 145 | + assert.NotNil(t, postResult.TaskItem) |
| 146 | + |
| 147 | + getRequestOpts := &requests.GetTaskOpts{ |
| 148 | + TaskUid: postResult.TaskItem.Uid, |
| 149 | + Name: remoteFileName, |
| 150 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 151 | + } |
| 152 | + getResult, _, err := client.TasksApi.GetTask(ctx, getRequestOpts) |
| 153 | + if err != nil { |
| 154 | + t.Error(err) |
| 155 | + } |
| 156 | + assert.Equal(t, int32(200), getResult.Code) |
| 157 | + assert.Equal(t, 18, len(getResult.Task.SubtasksUids)) |
| 158 | + |
| 159 | + var lastAddedSubtaskUid int32 |
| 160 | + for _, el := range getResult.Task.SubtasksUids { |
| 161 | + if el > lastAddedSubtaskUid { |
| 162 | + lastAddedSubtaskUid = el |
| 163 | + } |
| 164 | + } |
| 165 | + getRequestOpts.TaskUid = lastAddedSubtaskUid |
| 166 | + getResult, _, err = client.TasksApi.GetTask(ctx, getRequestOpts) |
| 167 | + if err != nil { |
| 168 | + t.Error(err) |
| 169 | + } |
| 170 | + assert.Equal(t, int32(200), getResult.Code) |
| 171 | + assert.Equal(t, CreateTime(2018, 12, 27, 8, 0, 0), getResult.Task.Start) |
| 172 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 173 | +} |
0 commit comments