@@ -34,19 +34,37 @@ class BlogActionsModelTests: AppTestCase {
3434 """ . data ( using: . utf8)
3535 }
3636
37- // MUT
38- let summaries = try BlogActions . Model ( ) . summaries
39-
40- XCTAssertEqual ( summaries. count, 2 )
41- let firstSummary = try XCTUnwrap ( summaries) . first
42-
43- // Note that we are testing that the first item in this list is the *last* item in the source YAML
44- // as the init should reverse the order of posts so that they display in reverse chronological order
45- XCTAssertEqual ( firstSummary, BlogActions . Model. PostSummary ( slug: " post-2 " ,
46- title: " Blog post title two " ,
47- summary: " Summary of blog post two " ,
48- publishedAt: DateFormatter . yearMonthDayDateFormatter. date ( from: " 2024-01-02 " ) !,
49- published: false ) )
37+ do { // Ensure dev shows all summaries
38+ Current . environment = { . development }
39+
40+ // MUT
41+ let summaries = BlogActions . Model ( ) . summaries
42+
43+ XCTAssertEqual ( summaries. count, 2 )
44+ XCTAssertEqual ( summaries. map ( \. slug) , [ " post-2 " , " post-1 " ] )
45+ XCTAssertEqual ( summaries. map ( \. published) , [ false , true ] )
46+
47+ let firstSummary = try XCTUnwrap ( summaries) . first
48+
49+ // Note that we are testing that the first item in this list is the *last* item in the source YAML
50+ // as the init should reverse the order of posts so that they display in reverse chronological order
51+ XCTAssertEqual ( firstSummary, BlogActions . Model. PostSummary ( slug: " post-2 " ,
52+ title: " Blog post title two " ,
53+ summary: " Summary of blog post two " ,
54+ publishedAt: DateFormatter . yearMonthDayDateFormatter. date ( from: " 2024-01-02 " ) !,
55+ published: false ) )
56+ }
57+
58+ do { // Ensure prod shows only published summaries
59+ Current . environment = { . production }
60+
61+ // MUT
62+ let summaries = BlogActions . Model ( ) . summaries
63+
64+ // validate
65+ XCTAssertEqual ( summaries. map ( \. slug) , [ " post-1 " ] )
66+ XCTAssertEqual ( summaries. map ( \. published) , [ true ] )
67+ }
5068 }
5169
5270 func test_postSummary_postMarkdown_load( ) async throws {
@@ -63,4 +81,15 @@ class BlogActionsModelTests: AppTestCase {
6381 XCTAssertEqual ( markdown, " <p>This is some Markdown with <a href= \" https://example.com \" >a link</a> and some <em>formatting</em>.</p> " )
6482 }
6583
84+ func test_decode_posts_yml( ) async throws {
85+ // setup
86+ Current . fileManager = . live
87+
88+ // MUT
89+ let summaries = try BlogActions . Model. allSummaries ( )
90+
91+ // validate
92+ XCTAssert ( summaries. count > 0 )
93+ }
94+
6695}
0 commit comments