Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension CoreDataRepository {
return await count(predicate: predicate, entityDesc: entityDesc, as: valueType)
default:
return await Self.send(
function: .sum,
function: function,
context: context,
predicate: predicate,
entityDesc: entityDesc,
Expand Down
107 changes: 107 additions & 0 deletions Tests/CoreDataRepositoryTests/AggregateRepositoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
}
}

func testCountSuccess_UnifiedEndpoint() async throws {
let result = try await repository().aggregate(
function: .count,
predicate: NSPredicate(value: true),
entityDesc: ManagedMovie.entity(),
attributeDesc: XCTUnwrap(
ManagedMovie.entity().attributesByName.values
.first(where: { $0.name == "boxOffice" })
),
as: Double.self
)
switch result {
case let .success(value):
XCTAssertEqual(value, 5, "Result value (count) should equal number of movies.")
case .failure:
XCTFail("Not expecting failure")
}
}

func testCountSubscription() async throws {
let task = Task {
var resultCount = 0
Expand Down Expand Up @@ -128,6 +147,25 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
}
}

func testSumSuccess_UnifiedEndpoint() async throws {
let result = try await repository().aggregate(
function: .sum,
predicate: NSPredicate(value: true),
entityDesc: ManagedMovie.entity(),
attributeDesc: XCTUnwrap(
ManagedMovie.entity().attributesByName.values
.first(where: { $0.name == "boxOffice" })
),
as: Decimal.self
)
switch result {
case let .success(value):
XCTAssertEqual(value, 150, "Result value (sum) should equal number of movies.")
case .failure:
XCTFail("Not expecting failure")
}
}

func testSumSubscription() async throws {
let task = Task {
var resultCount = 0
Expand Down Expand Up @@ -219,6 +257,29 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
}
}

func testAverageSuccess_UnifiedEndpoint() async throws {
let result = try await repository().aggregate(
function: .average,
predicate: NSPredicate(value: true),
entityDesc: ManagedMovie.entity(),
attributeDesc: XCTUnwrap(
ManagedMovie.entity().attributesByName.values
.first(where: { $0.name == "boxOffice" })
),
as: Decimal.self
)
switch result {
case let .success(value):
XCTAssertEqual(
value,
30,
"Result value should equal average of movies box office."
)
case .failure:
XCTFail("Not expecting failure")
}
}

func testAverageSubscription() async throws {
let task = Task {
var resultCount = 0
Expand Down Expand Up @@ -318,6 +379,29 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
}
}

func testMinSuccess_UnifiedEndpoint() async throws {
let result = try await repository().aggregate(
function: .min,
predicate: NSPredicate(value: true),
entityDesc: ManagedMovie.entity(),
attributeDesc: XCTUnwrap(
ManagedMovie.entity().attributesByName.values
.first(where: { $0.name == "boxOffice" })
),
as: Decimal.self
)
switch result {
case let .success(value):
XCTAssertEqual(
value,
10,
"Result value should equal min of movies box office."
)
case .failure:
XCTFail("Not expecting failure")
}
}

func testMinSubscription() async throws {
let task = Task {
var resultCount = 0
Expand Down Expand Up @@ -409,6 +493,29 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
}
}

func testMaxSuccess_UnifiedEndpoint() async throws {
let result = try await repository().aggregate(
function: .max,
predicate: NSPredicate(value: true),
entityDesc: ManagedMovie.entity(),
attributeDesc: XCTUnwrap(
ManagedMovie.entity().attributesByName.values
.first(where: { $0.name == "boxOffice" })
),
as: Decimal.self
)
switch result {
case let .success(value):
XCTAssertEqual(
value,
50,
"Result value should equal max of movies box office."
)
case .failure:
XCTFail("Not expecting failure")
}
}

func testMaxSubscription() async throws {
let task = Task {
var resultCount = 0
Expand Down