Skip to content
Repos

WO_DevPlaceIOS

Swift 2.5 KB73 lines Opens in site

Directory Raw Download

import Foundation
import Testing
@testable import DevPlaceSwiftSDK

struct NotificationSettingsDecodingTests {
    @Test func decodesSettingsFromTheNotificationsTab() throws {
        let settings = try JSONDecoder.devPlace.decode(NotificationSettings.CodingData.self, from: Data(Fixture.settings.utf8)).decoded

        #expect(settings.user.username == "fixtureuser")
        #expect(!settings.groupingEnabled)
        #expect(settings.throttlingEnabled)
        #expect(!settings.telegramPaired)
        #expect(settings.preferences.count == 2)

        let comments = try #require(settings.preferences.first)
        #expect(comments.key == "comment")
        #expect(comments.label == "Comments")
        #expect(comments.inApp)
        #expect(comments.push)
        #expect(!comments.telegram)
        #expect(!comments.customized)
    }

    @Test func channelsMatchTheBackendWireValues() {
        #expect(NotificationChannel.allCases.map(\.rawValue) == ["in_app", "push", "telegram"])
    }
}

private enum Fixture {
    static let settings = #"""
        {
            "profile_user": {
                "uid": "01a1dcbb-e4f3-7283-b9e5-6606d3abf6a4",
                "username": "fixtureuser",
                "avatar_seed": null,
                "bio": "",
                "location": "",
                "git_link": "",
                "website": "",
                "level": 1,
                "xp": 0,
                "xp_progress_pct": 0,
                "xp_next_level": 100,
                "stars": 0,
                "created_at": "2026-11-15T01:04:23.796522+00:00",
                "last_seen": "2026-11-15T01:18:57.645610+00:00"
            },
            "notif_grouping_enabled": false,
            "notif_throttle_enabled": true,
            "notif_telegram_paired": false,
            "notification_prefs": [
                {
                    "key": "comment",
                    "label": "Comments",
                    "description": "Someone comments on your post",
                    "in_app": true,
                    "push": true,
                    "telegram": false,
                    "customized": false
                },
                {
                    "key": "reply",
                    "label": "Replies",
                    "description": "Someone replies to your comment",
                    "in_app": true,
                    "push": true,
                    "telegram": false,
                    "customized": false
                }
            ]
        }
    """#
}
28.9ms