Skip to content

Commit

Permalink
fix: unfollow user fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MdTeach committed Jul 20, 2023
1 parent c2b23f5 commit 186e423
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 16 deletions.
13 changes: 10 additions & 3 deletions Sources/Endpoints/PushEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ extension PushEndpoint {
static func updateUser(
account userAddress: String,
env: ENV
) -> URL {
) -> Self {

// let endPoint = "https://" + ENV.getHost(withEnv: env) + "/apis/v2/users/\(userAddress)/profile"
// return URL(string: endPoint)!

let endPoint = "https://" + ENV.getHost(withEnv: env) + "/apis/v2/users/\(userAddress)/profile"
return URL(string: endPoint)!
PushEndpoint(
env: env,
path: "users/\(userAddress)/profile",
queryItems: [],
apiVersion: "v2"
)
}

static func getFeeds(
Expand Down
22 changes: 11 additions & 11 deletions Sources/User/UpdateProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension PushUser {
static func updateUserService(payload: UpdateUserPayload, account: String, env: ENV)
async throws
{
let url = PushEndpoint.updateUser(account: walletToPCAIP10(account: account), env: env)
let url = PushEndpoint.updateUser(account: walletToPCAIP10(account: account), env: env).url
var request = URLRequest(url: url)
request.httpMethod = "PUT"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
Expand All @@ -83,15 +83,15 @@ extension PushUser {
}

struct UpdateUserPayload: Codable {
var name: String?
var name: String
var desc: String
var picture: String
var blockedUsersList: [String]
var verificationProof: String
}

struct UpdateUseProfile: Codable {
public var name: String?
public var name: String
public var desc: String
public var picture: String
public var blockedUsersList: [String]
Expand All @@ -101,22 +101,22 @@ func getUpdateProfileHash(newProfile: PushUser.UserProfile) throws -> (
UpdateUseProfile, String
) {

let _name = newProfile.name == nil ? "" : newProfile.name!
let _desc = newProfile.desc == nil ? "" : newProfile.desc!
let _name = newProfile.name == nil ? " " : newProfile.name!
let _desc = newProfile.desc == nil ? " " : newProfile.desc!

let name = newProfile.name == nil ? "null" : "\"\(_name)\""
let desc = newProfile.desc == nil ? "null" : "\"\(_desc)\""
let name = "\"\(_name)\""
let desc = "\"\(_desc)\""
let picture = "\"\(newProfile.picture)\""
let blockedUsersList = newProfile.blockedUsersList!
let blockedUsersList = newProfile.blockedUsersList != nil ? newProfile.blockedUsersList! : []

let blockUserAddresses = flatten_address_list(addresses: newProfile.blockedUsersList!)
let jsonString =
"{\"name\":\(name),\"desc\":\(desc),\"picture\":\(picture),\"blockedUsersList\":\(blockUserAddresses)}"

let newUserProfile = UpdateUseProfile(
name: name.replacingOccurrences(of: "\"", with: ""),
desc: desc.replacingOccurrences(of: "\"", with: ""),
picture: picture.replacingOccurrences(of: "\"", with: ""),
name: _name,
desc: _desc,
picture: newProfile.picture,
blockedUsersList: blockedUsersList)
let hash = generateSHA256Hash(msg: jsonString)

Expand Down
69 changes: 67 additions & 2 deletions Tests/User/UpdateUserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UpdateUserTests: XCTestCase {

}

func testUserBlock() async throws {
func testUserBlockExistingUser() async throws {
let (a1, a2, a3) = (
generateRandomEthereumAddress(), generateRandomEthereumAddress(),
generateRandomEthereumAddress()
Expand All @@ -41,7 +41,37 @@ class UpdateUserTests: XCTestCase {
env: .STAGING)
}

func testUserUnBlock() async throws {
func testUserBlockCreatedUser() async throws {
let userPk = getRandomAccount()
let signer = try SignerPrivateKey(
privateKey: userPk
)
let addrs = try await signer.getAddress()

let user = try await PushUser.create(
options: PushUser.CreateUserOptions(
env: ENV.STAGING,
signer: signer,
progressHook: nil
))

let userPpgpPk = try await PushUser.DecryptPGPKey(
encryptedPrivateKey: user.encryptedPrivateKey, signer: signer)


let (a1, a2, a3) = (
generateRandomEthereumAddress(), generateRandomEthereumAddress(),
generateRandomEthereumAddress()
)

let usersToBlock = [a1, a2, a3]

try await PushUser.blockUsers(
addressesToBlock: usersToBlock, account: addrs, pgpPrivateKey: userPpgpPk,
env: .STAGING)
}

func testUserUnBlockExistingUser() async throws {
let (a1, a2, a3) = (
generateRandomEthereumAddress(), generateRandomEthereumAddress(),
generateRandomEthereumAddress()
Expand All @@ -59,4 +89,39 @@ class UpdateUserTests: XCTestCase {
env: .STAGING)
}

func testUserUnBlockCreatedUser() async throws {
let userPk = getRandomAccount()
let signer = try SignerPrivateKey(
privateKey: userPk
)
let addrs = try await signer.getAddress()

let user = try await PushUser.create(
options: PushUser.CreateUserOptions(
env: ENV.STAGING,
signer: signer,
progressHook: nil
))

let userPpgpPk = try await PushUser.DecryptPGPKey(
encryptedPrivateKey: user.encryptedPrivateKey, signer: signer)


let (a1, a2, a3) = (
generateRandomEthereumAddress(), generateRandomEthereumAddress(),
generateRandomEthereumAddress()
)

let usersToBlock = [a1, a2, a3]
let usersToUnBlock = [a1,a3]

try await PushUser.blockUsers(
addressesToBlock: usersToBlock, account: addrs, pgpPrivateKey: userPpgpPk,
env: .STAGING)

try await PushUser.unblockUsers(
addressesToUnblock: usersToUnBlock, account: UserAddress, pgpPrivateKey: UserPrivateKey,
env: .STAGING)
}

}

0 comments on commit 186e423

Please sign in to comment.