Skip to content

Commit

Permalink
Merge pull request #35 from okomari/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
vknabel authored Jul 3, 2020
2 parents b7c2d24 + 3270012 commit e2b89ca
Show file tree
Hide file tree
Showing 34 changed files with 341 additions and 168 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/dockerpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ on:
tags:
- v*

paths:
- ".github/workflows/**"
- ".swift-version"
- "PufferyServer/**"
- "APIDefinition/**"
- "Dockerfile"

# Run tests for any PRs.
pull_request:

Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Server

on:
push:
paths:
- ".github/workflows/**"
- ".swift-version"
- "PufferyServer/**"
- "APIDefinition/**"
pull_request:
paths:
- ".github/workflows/**"
- ".swift-version"
- "PufferyServer/**"
- "APIDefinition/**"

jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: puffery-test
POSTGRES_DB: puffery-test
POSTGRES_PASSWORD: puffery-test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis
env:
POSTGRES_USER: puffery-test
POSTGRES_DB: puffery-test
POSTGRES_PASSWORD: puffery-test
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- uses: actions/checkout@v2
- uses: YOCKOW/[email protected]
- name: Resolve
run: cd PufferyServer && swift package resolve
- name: Build
run: cd PufferyServer && swift build
- name: Run tests
run: cd PufferyServer && swift test --enable-test-discovery
env:
PUFFERY_IN_PROCESS_JOBS: "false"
DATABASE_URL: postgres://puffery-test:puffery-test@localhost:5432/puffery-test
REDIS_URL: redis://localhost:6379
18 changes: 0 additions & 18 deletions .github/workflows/swift.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Archerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ scripts:
- swift-test
- test-teardown
scripts:
generate-linux-main:
command: cd PufferyServer && swift test --generate-linuxmain
swift-test:
command: cd PufferyServer && swift test
env:
Expand Down
4 changes: 2 additions & 2 deletions Puffery/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

import APIDefinition
import CoreData
import Instabug
import PufferyKit
import UIKit
import UserNotifications
import Instabug

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var notifications = NoitifcationsService()

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = notifications

Instabug.start(withToken: "88e7078239c304aef087906e97d1d722", invocationEvents: [.shake, .screenshot])

return true
Expand Down
21 changes: 15 additions & 6 deletions PufferyKit/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"object": {
"pins": [
{
"package": "AckeeTracker",
"repositoryURL": "https://github.com/vknabel/AckeeTracker-Swift.git",
"package": "combine-schedulers",
"repositoryURL": "https://github.com/pointfreeco/combine-schedulers",
"state": {
"branch": null,
"revision": "1ba25182f92f2fbe088066d4b02f7d3c6561fec3",
"version": "0.1.0"
"revision": "afc84b6a3639198b7b8b6d79f04eb3c2ee590d29",
"version": "0.1.1"
}
},
{
Expand All @@ -19,13 +19,22 @@
"version": "19.0.0"
}
},
{
"package": "swift-case-paths",
"repositoryURL": "https://github.com/pointfreeco/swift-case-paths",
"state": {
"branch": null,
"revision": "fb733d87aabb5b053ad782902f2f3d67e0a65ac5",
"version": "0.1.1"
}
},
{
"package": "swift-composable-architecture",
"repositoryURL": "https://github.com/pointfreeco/swift-composable-architecture.git",
"state": {
"branch": null,
"revision": "bcb10ae7683636c126e99f751443e9464df726e8",
"version": "0.1.2"
"revision": "b8c67d5d4f27ad3b2f772cf50f91c581fc94611c",
"version": "0.6.0"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions PufferyKit/Sources/AckeeTracker/AckeeTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private extension AckeeTracker {
let deviceName: String?
#if canImport(UIKit)
deviceName = UIDevice.current.model
#else
deviceName = nil
#endif

let osName: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public struct FetchingError: Error, Identifiable, Equatable {
public static func == (lhs: FetchingError, rhs: FetchingError) -> Bool {
lhs.id == rhs.id
}

public var localizedDescription: String {
switch self.reason {
switch reason {
case let .http(error):
return error.localizedDescription
case let .encoding(error):
Expand Down
2 changes: 1 addition & 1 deletion PufferyKit/Sources/PufferyKit/Services/VaporAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ final class VaporAPI: API {
.encoding(body: createSubscription, using: jsonEncoder.encode)
.decoding(jsonDecoder.decode)
}

func update(subscription: SubscribedChannelResponse, updateSubscription: UpdateSubscriptionRequest) -> Endpoint<SubscribedChannelResponse> {
endpoint()
.post("api", "v1", "channels", subscription.id.uuidString)
Expand Down
52 changes: 37 additions & 15 deletions PufferyKit/Sources/PufferyUI/ActivityIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,47 @@
//

import SwiftUI
import UIKit
#if canImport(UIKit)
import UIKit

struct ActivityIndicator: UIViewRepresentable {
var isAnimating: Bool
var style: UIActivityIndicatorView.Style = .medium
struct ActivityIndicator: UIViewRepresentable {
typealias Style = UIActivityIndicatorView.Style
var isAnimating: Bool
var style: Style = .medium

func makeUIView(context _: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {
let indicator = UIActivityIndicatorView(style: style)
indicator.hidesWhenStopped = true
return indicator
func makeUIView(context _: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {
let indicator = UIActivityIndicatorView(style: style)
indicator.hidesWhenStopped = true
return indicator
}

func updateUIView(_ uiView: UIActivityIndicatorView, context _: UIViewRepresentableContext<ActivityIndicator>) {
isAnimating ? uiView.startAnimating() : uiView.stopAnimating()
}
}

struct UIActivityIndicator_Previews: PreviewProvider {
static var previews: some View {
ActivityIndicator(isAnimating: true, style: .large)
}
}
#else
struct ActivityIndicator: UIView {
enum Style {
case medium, large
}

var isAnimating: Bool
var style: Style = .medium

func updateUIView(_ uiView: UIActivityIndicatorView, context _: UIViewRepresentableContext<ActivityIndicator>) {
isAnimating ? uiView.startAnimating() : uiView.stopAnimating()
var body: some View {
Text("...")
}
}
}

struct ActivityIndicator_Previews: PreviewProvider {
static var previews: some View {
ActivityIndicator(isAnimating: true, style: .large)
struct TextActivityIndicator_Previews: PreviewProvider {
static var previews: some View {
ActivityIndicator(isAnimating: true, style: .large)
}
}
}
#endif
16 changes: 8 additions & 8 deletions PufferyKit/Sources/PufferyUI/ChannelCreationPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import UserNotifications
struct ChannelCreationPage: View {
@State var title: String = ""
@State var receiveNotifications: Bool = PushNotifications.hasBeenRequested

private var api: API { Current.api }

@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
Expand Down Expand Up @@ -52,24 +52,24 @@ struct ChannelCreationPage: View {
Text("Cancel")
}
}

func registerAndSetReceiveNotifications(_ newValue: Bool) {
if newValue == true, !PushNotifications.hasBeenRequested {
PushNotifications.register {
self.receiveNotifications = newValue
}
} else {
self.receiveNotifications = newValue
receiveNotifications = newValue
}
}

func createChannel() {
if self.isUUID {
self.api.subscribe(CreateSubscriptionRequest(receiveOrNotifyKey: self.title, isSilent: !self.receiveNotifications))
.task(self.receiveChannel(result:))
if isUUID {
api.subscribe(CreateSubscriptionRequest(receiveOrNotifyKey: title, isSilent: !receiveNotifications))
.task(receiveChannel(result:))
} else {
self.api.createChannel(CreateChannelRequest(title: self.title, isSilent: !self.receiveNotifications))
.task(self.receiveChannel(result:))
api.createChannel(CreateChannelRequest(title: title, isSilent: !receiveNotifications))
.task(receiveChannel(result:))
}
}

Expand Down
2 changes: 1 addition & 1 deletion PufferyKit/Sources/PufferyUI/ChannelListPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct ChannelListPage: View {
@State var selection: ChannelSelection? = UIDevice.current.model == "iPad"
? .all
: nil

var body: some View {
ZStack {
List {
Expand Down
16 changes: 8 additions & 8 deletions PufferyKit/Sources/PufferyUI/ChannelSettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ struct ChannelSettingsPage: View {

var body: some View {
List {
Section() {
Section {
HStack {
Text("ChannelSettings.Basic.Name")
Spacer()
Text(channel.title)
.foregroundColor(.secondary)
}

Toggle("ChannelSettings.Basic.ReceiveNotifications", isOn: Binding(get: { !self.channel.isSilent }, set: self.registerAndSetReceiveNotifications))
}

Section(header: Text("ChannelSettings.Share.Title"), footer: Text("ChannelSettings.Share.Explanation")) {
channel.notifyKey.map { notifyKey in
CopyContentsCell(
Expand Down Expand Up @@ -134,22 +134,22 @@ struct ChannelSettingsPage: View {
}
}
}

func registerAndSetReceiveNotifications(_ newValue: Bool) {
if newValue == true, !PushNotifications.hasBeenRequested {
PushNotifications.register {
self.channel.isSilent = !newValue
}
} else {
self.channel.isSilent = !newValue
channel.isSilent = !newValue
}

Current.api.update(subscription: channel, updateSubscription: UpdateSubscriptionRequest(isSilent: channel.isSilent))
.task({ _ in
.task { _ in
DispatchQueue.main.async {
NotificationCenter.default.post(name: .didChangeChannel, object: nil)
}
})
}
}

func save() {
Expand Down
8 changes: 4 additions & 4 deletions PufferyKit/Sources/PufferyUI/ChannelSubscribingPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ struct ChannelSubscribingPage: View {
Text("ChannelSubscribing.Cancel")
}
}

func registerAndSetReceiveNotifications(_ newValue: Bool) {
if newValue == true, !PushNotifications.hasBeenRequested {
PushNotifications.register {
self.receiveNotifications = newValue
}
} else {
self.receiveNotifications = newValue
receiveNotifications = newValue
}
}

func createChannel() {
self.api.subscribe(CreateSubscriptionRequest(receiveOrNotifyKey: self.channelKey, isSilent: !self.receiveNotifications))
.task(self.receiveChannel(result:))
api.subscribe(CreateSubscriptionRequest(receiveOrNotifyKey: channelKey, isSilent: !receiveNotifications))
.task(receiveChannel(result:))
}

func receiveChannel(result: Result<SubscribedChannelResponse, FetchingError>) {
Expand Down
Loading

0 comments on commit e2b89ca

Please sign in to comment.