Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
Elixxir dApps SDK Swift
Commits
f84c676c
Commit
f84c676c
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Add MessageService model
parent
ce5ae808
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!102
Release 1.0.0
,
!60
Update Bindings
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/XXClient/Models/MessageService.swift
+43
-0
43 additions, 0 deletions
Sources/XXClient/Models/MessageService.swift
Tests/XXClientTests/Models/MessageServiceTests.swift
+56
-0
56 additions, 0 deletions
Tests/XXClientTests/Models/MessageServiceTests.swift
with
99 additions
and
0 deletions
Sources/XXClient/Models/MessageService.swift
0 → 100644
+
43
−
0
View file @
f84c676c
import
Foundation
public
struct
MessageService
:
Equatable
{
public
init
(
identifier
:
Data
,
tag
:
String
,
metadata
:
Data
)
{
self
.
identifier
=
identifier
self
.
tag
=
tag
self
.
metadata
=
metadata
}
public
var
identifier
:
Data
public
var
tag
:
String
public
var
metadata
:
Data
}
extension
MessageService
:
Codable
{
enum
CodingKeys
:
String
,
CodingKey
{
case
identifier
=
"Identifier"
case
tag
=
"Tag"
case
metadata
=
"Metadata"
}
public
static
func
decode
(
_
data
:
Data
)
throws
->
Self
{
try
JSONDecoder
()
.
decode
(
Self
.
self
,
from
:
data
)
}
public
func
encode
()
throws
->
Data
{
try
JSONEncoder
()
.
encode
(
self
)
}
}
extension
Array
where
Element
==
MessageService
{
public
static
func
decode
(
_
data
:
Data
)
throws
->
Self
{
try
JSONDecoder
()
.
decode
(
Self
.
self
,
from
:
data
)
}
public
func
encode
()
throws
->
Data
{
try
JSONEncoder
()
.
encode
(
self
)
}
}
This diff is collapsed.
Click to expand it.
Tests/XXClientTests/Models/MessageServiceTests.swift
0 → 100644
+
56
−
0
View file @
f84c676c
import
CustomDump
import
XCTest
@testable
import
XXClient
final
class
MessageServiceTests
:
XCTestCase
{
func
testCoding
()
throws
{
let
identifierB64
=
"AQID"
let
tag
=
"TestTag 2"
let
metadataB64
=
"BAUG"
let
jsonString
=
"""
{
"
Identifier
": "
\(
identifierB64
)
",
"
Tag
": "
\(
tag
)
",
"
Metadata
": "
\(
metadataB64
)
"
}
"""
let
jsonData
=
jsonString
.
data
(
using
:
.
utf8
)
!
let
model
=
try
MessageService
.
decode
(
jsonData
)
XCTAssertNoDifference
(
model
,
MessageService
(
identifier
:
Data
(
base64Encoded
:
identifierB64
)
!
,
tag
:
tag
,
metadata
:
Data
(
base64Encoded
:
metadataB64
)
!
))
let
encodedModel
=
try
model
.
encode
()
let
decodedModel
=
try
MessageService
.
decode
(
encodedModel
)
XCTAssertNoDifference
(
decodedModel
,
model
)
}
func
testCodingArray
()
throws
{
let
models
=
[
MessageService
(
identifier
:
"service1-id"
.
data
(
using
:
.
utf8
)
!
,
tag
:
"service1-tag"
,
metadata
:
"service1-metadata"
.
data
(
using
:
.
utf8
)
!
),
MessageService
(
identifier
:
"service2-id"
.
data
(
using
:
.
utf8
)
!
,
tag
:
"service2-tag"
,
metadata
:
"service2-metadata"
.
data
(
using
:
.
utf8
)
!
),
MessageService
(
identifier
:
"service3-id"
.
data
(
using
:
.
utf8
)
!
,
tag
:
"service3-tag"
,
metadata
:
"service3-metadata"
.
data
(
using
:
.
utf8
)
!
),
]
let
encodedModels
=
try
models
.
encode
()
let
decodedModels
=
try
[
MessageService
]
.
decode
(
encodedModels
)
XCTAssertNoDifference
(
models
,
decodedModels
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment