All files / app/test serviceMockDefaults.ts

94.28% Statements 33/35
100% Branches 6/6
83.33% Functions 10/12
94.28% Lines 33/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209    23x         23x 23x 23x 23x   23x   23x                       23x 288x     23x 7x 7x     23x 14x             23x                                       23x                                     23x 16x                     23x 59x   10x               40x                         9x       23x 17x                                           23x 17x                                                                                   23x 2x           23x 10x           23x 11x          
import { User } from "proto/api_pb";
import { ListAdminsRes } from "proto/communities_pb";
import { HostRequestStatus } from "proto/conversations_pb";
import { ListEventAttendeesRes, ListEventOrganizersRes } from "proto/events_pb";
import {
  AvailableWriteReferencesRes,
  ReferenceType,
} from "proto/references_pb";
import comments from "test/fixtures/comments.json";
import messages from "test/fixtures/messages.json";
import users from "test/fixtures/users.json";
 
const [user1, user2, user3, user4, user5] = users;
 
const userMap: Record<string, User.AsObject> = {
  "1": user1,
  "2": user2,
  "3": user3,
  "4": user4,
  "5": user5,
  funnycat: user1,
  funnyChicken: user4,
  funnydog: user2,
  funnykid: user3,
};
 
export async function getUser(userId: string): Promise<User.AsObject> {
  return userMap[userId];
}
 
export async function listFriends() {
  const [, user2, user3] = users;
  return [user2.userId, user3.userId];
}
 
export async function getGroupChatMessages() {
  return {
    lastMessageId: 5,
    messagesList: messages,
    noMore: true,
  };
}
 
export async function listGroupChats() {
  return {
    groupChatsList: [
      {
        adminUserIdsList: [],
        groupChatId: 3,
        isDm: false,
        lastSeenMessageId: 4,
        latestMessage: messages[0],
        memberUserIdsList: [],
        onlyAdminsInvite: true,
        title: "groupchattitle",
        // created?: google_protobuf_timestamp_pb.Timestamp.AsObject,
        unseenMessageCount: 0,
      },
    ],
    noMore: true,
  };
}
 
export async function listHostRequests() {
  return [
    {
      created: {
        nanos: 0,
        seconds: Date.now() / 1000,
      },
      fromDate: "2020/12/01",
      surferUserId: 1,
      hostRequestId: 1,
      lastSeenMessageId: 0,
      latestMessage: messages[0],
      status: HostRequestStatus.HOST_REQUEST_STATUS_PENDING,
      toDate: "2020/12/06",
      hostUserId: 2,
    },
  ];
}
 
export async function getAvailableReferences(): Promise<AvailableWriteReferencesRes.AsObject> {
  return {
    canWriteFriendReference: true,
    availableWriteReferencesList: [
      {
        hostRequestId: 1,
        referenceType: ReferenceType.REFERENCE_TYPE_HOSTED,
      },
    ],
  };
}
 
export async function getThread(threadId: number) {
  switch (threadId) {
    case 2:
      return {
        nextPageToken: "",
        repliesList: comments.slice(0, 4),
      };
    case 3:
    case 4:
    case 5:
    case 6:
      return {
        nextPageToken: "",
        repliesList: [
          {
            threadId: threadId * 3,
            content: `+${threadId}`,
            authorUserId: 3,
            createdTime: { seconds: 1577920000, nanos: 0 },
            numReplies: 0,
          },
        ],
      };
    default:
      return { nextPageToken: "", repliesList: [] };
  }
}
 
export async function getLanguages() {
  return {
    languagesList: [
      {
        code: "eng",
        name: "English",
      },
      {
        code: "fra",
        name: "French",
      },
      {
        code: "fin",
        name: "Finnish",
      },
      {
        code: "spa",
        name: "Spanish",
      },
    ],
  };
}
 
export async function getRegions() {
  return {
    regionsList: [
      {
        alpha3: "USA",
        name: "United States",
      },
      {
        alpha3: "FRA",
        name: "France",
      },
      {
        alpha3: "FIN",
        name: "Finland",
      },
      {
        alpha3: "ESP",
        name: "Spain",
      },
      {
        alpha3: "AUS",
        name: "Australia",
      },
      {
        alpha3: "SWE",
        name: "Sweden",
      },
      {
        alpha3: "CMR",
        name: "Cameroon",
      },
      {
        alpha3: "JPN",
        name: "Japan",
      },
      {
        alpha3: "GBR",
        name: "United Kingdom",
      },
    ],
  };
}
 
export async function listCommunityAdmins(): Promise<ListAdminsRes.AsObject> {
  return {
    adminUserIdsList: [2, 3],
    nextPageToken: "",
  };
}
 
export async function getEventOrganizers(): Promise<ListEventOrganizersRes.AsObject> {
  return {
    organizerUserIdsList: [2, 3],
    nextPageToken: "",
  };
}
 
export async function getEventAttendees(): Promise<ListEventAttendeesRes.AsObject> {
  return {
    attendeeUserIdsList: [1, 4],
    nextPageToken: "",
  };
}