Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding relative reminder #25

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions src/Todoist.Net.Tests/Services/ReminersServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;

using Todoist.Net.Models;
using Todoist.Net.Tests.Extensions;
Expand All @@ -21,25 +22,51 @@ public ReminersServiceTests(ITestOutputHelper outputHelper)
}

[Fact]
public void CreateDelete_Success()
public async Task CreateDelete_Success()
{
var client = TodoistClientFactory.Create(_outputHelper);

var transaction = client.CreateTransaction();

var itemId = transaction.Items.AddAsync(new Item("Temp")).Result;
var itemId = await transaction.Items.AddAsync(new Item("Temp")).ConfigureAwait(false);
var reminderId =
transaction.Reminders.AddAsync(new Reminder(itemId) { DueDate = new DueDate(DateTime.UtcNow.AddDays(1)) }).Result;
transaction.CommitAsync().Wait();
await transaction.Reminders.AddAsync(new Reminder(itemId) { DueDate = new DueDate(DateTime.UtcNow.AddDays(1)) }).ConfigureAwait(false);
await transaction.CommitAsync().ConfigureAwait(false);

var reminders = client.Reminders.GetAsync().Result;
var reminders = await client.Reminders.GetAsync().ConfigureAwait(false);
Assert.True(reminders.Any());

var reminderInfo = client.Reminders.GetAsync(reminderId).Result;
var reminderInfo = await client.Reminders.GetAsync(reminderId).ConfigureAwait(false);
Assert.True(reminderInfo != null);

client.Reminders.DeleteAsync(reminderInfo.Reminder.Id).Wait();
client.Items.DeleteAsync(itemId);
await client.Reminders.DeleteAsync(reminderInfo.Reminder.Id).ConfigureAwait(false);
await client.Items.DeleteAsync(itemId);
}

[Fact]
public async Task AddRelativeReminder_Success()
{
var client = TodoistClientFactory.Create(_outputHelper);

var item = new Item("Test")
{
DueDate = new DueDate(DateTime.UtcNow.AddDays(1))
};

var taskId = await client.Items.AddAsync(item).ConfigureAwait(false);

var user = await client.Users.GetCurrentAsync().ConfigureAwait(false);
var reminder = new Reminder(taskId)
{
MinuteOffset = 60,
NotifyUid = user.Id
};

var reminderId = await client.Reminders.AddAsync(reminder).ConfigureAwait(false);

Assert.NotNull(reminderId.PersistentId);

await client.Items.DeleteAsync(item.Id);
}
}
}
2 changes: 1 addition & 1 deletion src/Todoist.Net.Tests/Services/UsersServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task GetCurrentAsync_Success()
var user = await client.Users.GetCurrentAsync();

Assert.NotNull(user);
Assert.True(user.Id > 0);
Assert.NotNull(user.Id);
}

[Fact]
Expand Down
6 changes: 5 additions & 1 deletion src/Todoist.Net/Models/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ internal BaseEntity()
[JsonProperty("id")]
public ComplexId Id { get; set; }

internal bool ShouldSerializeId()
/// <summary>
/// Checks if the Id property should be serialized.
/// </summary>
/// <returns><c>True</c> if the property should be serialized, <c>false</c> otherwise.</returns>
public bool ShouldSerializeId()
{
return !Id.IsEmpty;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Todoist.Net/Models/Reminder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal Reminder()
/// <value>The mm offset.</value>
/// <remarks>The relative time in minutes before the due date of the item, in which the reminder should be triggered.
/// Note, that the item should have a due date set in order to add a relative reminder.</remarks>
[JsonProperty("mm_offset")]
[JsonProperty("minute_offset")]
public long? MinuteOffset { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Todoist.Net/Models/ReminderType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ private ReminderType(string value)
/// </summary>
/// <value>The relative.</value>
/// <remarks>For a time-based reminder specified in minutes from now.</remarks>
public static ReminderType Relative { get; } = new ReminderType("relative ");
public static ReminderType Relative { get; } = new ReminderType("relative");
}
}
2 changes: 1 addition & 1 deletion src/Todoist.Net/Models/UserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal UserInfo()
/// </summary>
/// <value>The identifier.</value>
[JsonProperty("id")]
public int Id { get; internal set; }
public string Id { get; internal set; }

/// <summary>
/// Gets the image identifier.
Expand Down