restructure
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
This commit is contained in:
148
iOS/RSSuperTests/FeedItemTests.swift
Normal file
148
iOS/RSSuperTests/FeedItemTests.swift
Normal file
@@ -0,0 +1,148 @@
|
||||
//
|
||||
// FeedItemTests.swift
|
||||
// RSSuperTests
|
||||
//
|
||||
// Created by Mike Freno on 3/29/26.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import RSSuper
|
||||
|
||||
final class FeedItemTests: XCTestCase {
|
||||
|
||||
func testFeedItemEncodingDecoding() throws {
|
||||
let item = FeedItem(
|
||||
id: "550e8400-e29b-41d4-a716-446655440000",
|
||||
title: "Test Article",
|
||||
link: "https://example.com/article",
|
||||
description: "A test description",
|
||||
content: "Full content here",
|
||||
author: "John Doe",
|
||||
published: Date(millisecondsSince1970: 1609459200000),
|
||||
categories: ["tech", "swift"],
|
||||
enclosure: Enclosure(url: "https://example.com/audio.mp3", type: "audio/mpeg", length: 1234567),
|
||||
guid: "guid-123",
|
||||
subscriptionId: "sub-123",
|
||||
subscriptionTitle: "Test Feed"
|
||||
)
|
||||
|
||||
let data = try JSONEncoder().encode(item)
|
||||
let decoded = try JSONDecoder().decode(FeedItem.self, from: data)
|
||||
|
||||
XCTAssertEqual(decoded.id, item.id)
|
||||
XCTAssertEqual(decoded.title, item.title)
|
||||
XCTAssertEqual(decoded.link, item.link)
|
||||
XCTAssertEqual(decoded.description, item.description)
|
||||
XCTAssertEqual(decoded.content, item.content)
|
||||
XCTAssertEqual(decoded.author, item.author)
|
||||
XCTAssertEqual(decoded.published, item.published)
|
||||
XCTAssertEqual(decoded.categories, item.categories)
|
||||
XCTAssertEqual(decoded.guid, item.guid)
|
||||
XCTAssertEqual(decoded.subscriptionId, item.subscriptionId)
|
||||
XCTAssertEqual(decoded.subscriptionTitle, item.subscriptionTitle)
|
||||
}
|
||||
|
||||
func testFeedItemOptionalProperties() throws {
|
||||
let item = FeedItem(
|
||||
id: "test-id",
|
||||
title: "Minimal Item",
|
||||
subscriptionId: "sub-id"
|
||||
)
|
||||
|
||||
XCTAssertNil(item.link)
|
||||
XCTAssertNil(item.description)
|
||||
XCTAssertNil(item.content)
|
||||
XCTAssertNil(item.author)
|
||||
XCTAssertNil(item.published)
|
||||
XCTAssertNil(item.categories)
|
||||
XCTAssertNil(item.enclosure)
|
||||
XCTAssertNil(item.guid)
|
||||
XCTAssertNil(item.subscriptionTitle)
|
||||
|
||||
let data = try JSONEncoder().encode(item)
|
||||
let decoded = try JSONDecoder().decode(FeedItem.self, from: data)
|
||||
|
||||
XCTAssertEqual(decoded.id, item.id)
|
||||
XCTAssertEqual(decoded.title, item.title)
|
||||
}
|
||||
|
||||
func testEnclosureEncodingDecoding() throws {
|
||||
let enclosure = Enclosure(
|
||||
url: "https://example.com/podcast.mp3",
|
||||
type: "audio/mpeg",
|
||||
length: 98765432
|
||||
)
|
||||
|
||||
let data = try JSONEncoder().encode(enclosure)
|
||||
let decoded = try JSONDecoder().decode(Enclosure.self, from: data)
|
||||
|
||||
XCTAssertEqual(decoded.url, enclosure.url)
|
||||
XCTAssertEqual(decoded.type, enclosure.type)
|
||||
XCTAssertEqual(decoded.length, enclosure.length)
|
||||
}
|
||||
|
||||
func testEnclosureWithoutLength() throws {
|
||||
let enclosure = Enclosure(
|
||||
url: "https://example.com/video.mp4",
|
||||
type: "video/mp4"
|
||||
)
|
||||
|
||||
let data = try JSONEncoder().encode(enclosure)
|
||||
let decoded = try JSONDecoder().decode(Enclosure.self, from: data)
|
||||
|
||||
XCTAssertEqual(decoded.url, enclosure.url)
|
||||
XCTAssertEqual(decoded.type, enclosure.type)
|
||||
XCTAssertNil(decoded.length)
|
||||
}
|
||||
|
||||
func testFeedItemEquality() {
|
||||
let item1 = FeedItem(
|
||||
id: "same-id",
|
||||
title: "Same Title",
|
||||
subscriptionId: "sub-id"
|
||||
)
|
||||
|
||||
let item2 = FeedItem(
|
||||
id: "same-id",
|
||||
title: "Same Title",
|
||||
subscriptionId: "sub-id"
|
||||
)
|
||||
|
||||
let item3 = FeedItem(
|
||||
id: "different-id",
|
||||
title: "Different Title",
|
||||
subscriptionId: "sub-id"
|
||||
)
|
||||
|
||||
XCTAssertEqual(item1, item2)
|
||||
XCTAssertNotEqual(item1, item3)
|
||||
}
|
||||
|
||||
func testContentTypeDetection() {
|
||||
let audioEnclosure = Enclosure(url: "test.mp3", type: "audio/mpeg")
|
||||
XCTAssertEqual(audioEnclosure.mimeType, .audio)
|
||||
|
||||
let videoEnclosure = Enclosure(url: "test.mp4", type: "video/mp4")
|
||||
XCTAssertEqual(videoEnclosure.mimeType, .video)
|
||||
|
||||
let articleEnclosure = Enclosure(url: "test.pdf", type: "application/pdf")
|
||||
XCTAssertEqual(articleEnclosure.mimeType, .article)
|
||||
}
|
||||
|
||||
func testFeedItemDebugDescription() {
|
||||
let item = FeedItem(
|
||||
id: "test-id",
|
||||
title: "Debug Test",
|
||||
author: "Test Author",
|
||||
published: Date(millisecondsSince1970: 1609459200000),
|
||||
subscriptionId: "sub-id",
|
||||
subscriptionTitle: "My Feed"
|
||||
)
|
||||
|
||||
let debugDesc = item.debugDescription
|
||||
XCTAssertTrue(debugDesc.contains("test-id"))
|
||||
XCTAssertTrue(debugDesc.contains("Debug Test"))
|
||||
XCTAssertTrue(debugDesc.contains("Test Author"))
|
||||
XCTAssertTrue(debugDesc.contains("My Feed"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user