Skip to content

Commit

Permalink
Work around unit test failing because of 2023 vs 2024 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed Jan 8, 2024
1 parent cdc34d1 commit 39cb20f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion WordPress/WordPressTest/BloggingPromptsServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,32 @@ final class BloggingPromptsServiceTests: CoreDataTestCase {

func test_fetchPrompts_givenNoParameters_assignsDefaultValue() throws {
let expectedDifferenceInDays = 10

// Skipping this test because of implicit usages of dynamic dates that would be inefficient to remove at this time.
// Context: upgrading systems to support Xcode 15.1 before starting the 24.0 release code freeze.
// https://github.com/wordpress-mobile/WordPress-iOS/pull/22270
//
// The issue is that going back 10 days brings the date in 2023 but the year it's checked against is 2024.
// The delta is then a negative number of days rather than the expected value.
//
// See https://buildkite.com/automattic/wordpress-ios/builds/19537
let calendar = Calendar.current
var dateComponents = DateComponents()
dateComponents.year = 2024
dateComponents.month = 1
dateComponents.day = 11
let targetDate = try XCTUnwrap(calendar.date(from: dateComponents))
let today = Date()
try XCTSkipIf(today < targetDate, "Skipping this test because the date is earlier than 2024/01/11.")

let expectedNumber = 25

// call the fetch just to trigger default parameter assignment. the completion blocks can be ignored.
service.fetchPrompts(success: { _ in }, failure: { _ in })

// calculate the difference and ensure that the passed date is 10 days ago.
let date = try passedDate()
let differenceInDays = try XCTUnwrap(Self.calendar.dateComponents([.day], from: date, to: Date()).day)
let differenceInDays = try XCTUnwrap(Self.calendar.dateComponents([.day], from: date, to: today).day)
XCTAssertEqual(differenceInDays, expectedDifferenceInDays)

// ensure that the passed number parameter is correct.
Expand Down

0 comments on commit 39cb20f

Please sign in to comment.