Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions apps/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
},
"dependencies": {
"@formbricks/react-native": "workspace:*",
"@react-native-async-storage/async-storage": "2.1.2",
"expo": "~53.0.13",
"expo-status-bar": "~2.2.3",
"react": "19.0.0",
"react-native": "0.79.4"
"@react-native-async-storage/async-storage": "2.2.0",
"expo": "54.0.29",
"expo-status-bar": "3.0.9",
"react": "19.1.0",
"react-native": "0.81.5"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@types/react": "~19.0.10",
"typescript": "~5.8.3"
"@babel/core": "7.28.5",
"@types/react": "19.1.17",
"typescript": "5.9.3"
},
"private": true
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
},
"pnpm": {
"overrides": {
"on-headers": ">=1.1.0"
"on-headers": ">=1.1.0",
"glob": ">=11.1.0",
"node-forge": ">=1.3.2",
"js-yaml": ">=4.1.1"
}
}
}
14 changes: 7 additions & 7 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
"zod": "3.25.67"
},
"devDependencies": {
"@types/react": "19.0.14",
"@types/react": "19.1.17",
"@vercel/style-guide": "6.0.0",
"@vitest/coverage-v8": "3.2.4",
"react": "19.0.0",
"react-native": "0.79.4",
"terser": "5.37.0",
"vite": "7.1.9",
"@vitest/coverage-v8": "4.0.15",
"react": "19.1.0",
"react-native": "0.81.5",
"terser": "5.44.1",
"vite": "7.3.0",
"vite-plugin-dts": "4.5.4",
"vitest": "3.2.4"
"vitest": "4.0.15"
},
"peerDependencies": {
"@react-native-async-storage/async-storage": ">=2.1.0",
Expand Down
44 changes: 24 additions & 20 deletions packages/react-native/src/lib/environment/tests/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import {

// Mock the FormbricksAPI so we can control environment.getState
vi.mock("@/lib/common/api", () => ({
ApiClient: vi.fn().mockImplementation(() => ({
getEnvironmentState: vi.fn(),
})),
ApiClient: vi.fn().mockImplementation(function () {
return { getEnvironmentState: vi.fn() };
}),
}));

// Mock logger (so we don’t spam console)
Expand Down Expand Up @@ -70,7 +70,7 @@ describe("environment/state.ts", () => {
describe("fetchEnvironmentState()", () => {
test("returns ok(...) with environment state", async () => {
// Setup mock
(ApiClient as unknown as Mock).mockImplementationOnce(() => {
(ApiClient as unknown as Mock).mockImplementationOnce(function () {
return {
getEnvironmentState: vi.fn().mockResolvedValue({
ok: true,
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("environment/state.ts", () => {
message: "Access denied",
};

(ApiClient as unknown as Mock).mockImplementationOnce(() => {
(ApiClient as unknown as Mock).mockImplementationOnce(function () {
return {
getEnvironmentState: vi.fn().mockResolvedValue({
ok: false,
Expand Down Expand Up @@ -131,7 +131,7 @@ describe("environment/state.ts", () => {
responseMessage: "Network fail",
};

(ApiClient as unknown as Mock).mockImplementationOnce(() => {
(ApiClient as unknown as Mock).mockImplementationOnce(function () {
return {
getEnvironmentState: vi.fn().mockRejectedValue(mockNetworkError),
};
Expand Down Expand Up @@ -208,12 +208,14 @@ describe("environment/state.ts", () => {

mockRNConfig.mockReturnValue(mockConfig as unknown as Promise<RNConfig>);

(ApiClient as Mock).mockImplementation(() => ({
getEnvironmentState: vi.fn().mockResolvedValue({
ok: true,
data: mockNewState,
}),
}));
(ApiClient as Mock).mockImplementation(function () {
return {
getEnvironmentState: vi.fn().mockResolvedValue({
ok: true,
data: mockNewState,
}),
};
});

(filterSurveys as Mock).mockReturnValue([]);

Expand Down Expand Up @@ -242,11 +244,13 @@ describe("environment/state.ts", () => {
mockRNConfig.mockReturnValue(mockConfig as unknown as Promise<RNConfig>);

// Mock API to throw an error
(ApiClient as Mock).mockImplementation(() => ({
getEnvironmentState: vi
.fn()
.mockRejectedValue(new Error("Network error")),
}));
(ApiClient as Mock).mockImplementation(function () {
return {
getEnvironmentState: vi
.fn()
.mockRejectedValue(new Error("Network error")),
};
});

addEnvironmentStateExpiryCheckListener();

Expand All @@ -272,9 +276,9 @@ describe("environment/state.ts", () => {

mockRNConfig.mockReturnValue(mockConfig as unknown as Promise<RNConfig>);

const apiMock = vi.fn().mockImplementation(() => ({
getEnvironmentState: vi.fn(),
}));
const apiMock = vi.fn().mockImplementation(function () {
return { getEnvironmentState: vi.fn() };
});

(ApiClient as Mock).mockImplementation(apiMock);

Expand Down
95 changes: 64 additions & 31 deletions packages/react-native/src/lib/user/tests/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ vi.mock("@/lib/common/utils", () => ({
}));

vi.mock("@/lib/common/api", () => ({
ApiClient: vi.fn().mockImplementation(() => ({
createOrUpdateUser: vi.fn(),
})),
ApiClient: vi.fn().mockImplementation(function () {
return { createOrUpdateUser: vi.fn() };
}),
}));

describe("sendUpdatesToBackend", () => {
Expand All @@ -56,9 +56,9 @@ describe("sendUpdatesToBackend", () => {
},
};

(ApiClient as Mock).mockImplementation(() => ({
createOrUpdateUser: vi.fn().mockResolvedValue(mockResponse),
}));
(ApiClient as Mock).mockImplementation(function () {
return { createOrUpdateUser: vi.fn().mockResolvedValue(mockResponse) };
});

const result = await sendUpdatesToBackend({
appUrl: mockAppUrl,
Expand All @@ -68,19 +68,31 @@ describe("sendUpdatesToBackend", () => {

expect(result.ok).toBe(true);
if (result.ok) {
expect(result.data.state.data).toEqual({ userId: mockUserId, attributes: mockAttributes });
expect(result.data.state.data).toEqual({
userId: mockUserId,
attributes: mockAttributes,
});
}
});

test("returns network error if API call fails", async () => {
const mockUpdates: TUpdates = { userId: mockUserId, attributes: mockAttributes };
const mockUpdates: TUpdates = {
userId: mockUserId,
attributes: mockAttributes,
};

(ApiClient as Mock).mockImplementation(() => ({
createOrUpdateUser: vi.fn().mockResolvedValue({
ok: false,
error: { code: "network_error", message: "Request failed", status: 500 },
}),
}));
(ApiClient as Mock).mockImplementation(function () {
return {
createOrUpdateUser: vi.fn().mockResolvedValue({
ok: false,
error: {
code: "network_error",
message: "Request failed",
status: 500,
},
}),
};
});

const result = await sendUpdatesToBackend({
appUrl: mockAppUrl,
Expand All @@ -91,16 +103,25 @@ describe("sendUpdatesToBackend", () => {
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.error.code).toBe("network_error");
expect(result.error.message).toBe("Error updating user with userId user_123");
expect(result.error.message).toBe(
"Error updating user with userId user_123"
);
}
});

test("throws error if network request fails", async () => {
const mockUpdates: TUpdates = { userId: mockUserId, attributes: { plan: "premium" } };
const mockUpdates: TUpdates = {
userId: mockUserId,
attributes: { plan: "premium" },
};

(ApiClient as Mock).mockImplementation(() => ({
createOrUpdateUser: vi.fn().mockRejectedValue(new Error("Network error")),
}));
(ApiClient as Mock).mockImplementation(function () {
return {
createOrUpdateUser: vi
.fn()
.mockRejectedValue(new Error("Network error")),
};
});

await expect(
sendUpdatesToBackend({
Expand Down Expand Up @@ -146,11 +167,13 @@ describe("sendUpdates", () => {
},
};

(ApiClient as Mock).mockImplementation(() => ({
createOrUpdateUser: vi.fn().mockResolvedValue(mockResponse),
}));
(ApiClient as Mock).mockImplementation(function () {
return { createOrUpdateUser: vi.fn().mockResolvedValue(mockResponse) };
});

const result = await sendUpdates({ updates: { userId: mockUserId, attributes: mockAttributes } });
const result = await sendUpdates({
updates: { userId: mockUserId, attributes: mockAttributes },
});

expect(result.ok).toBe(true);
});
Expand All @@ -165,11 +188,15 @@ describe("sendUpdates", () => {
},
};

(ApiClient as Mock).mockImplementation(() => ({
createOrUpdateUser: vi.fn().mockResolvedValue(mockErrorResponse),
}));
(ApiClient as Mock).mockImplementation(function () {
return {
createOrUpdateUser: vi.fn().mockResolvedValue(mockErrorResponse),
};
});

const result = await sendUpdates({ updates: { userId: mockUserId, attributes: mockAttributes } });
const result = await sendUpdates({
updates: { userId: mockUserId, attributes: mockAttributes },
});

expect(result.ok).toBe(false);
if (!result.ok) {
Expand All @@ -178,11 +205,17 @@ describe("sendUpdates", () => {
});

test("handles unexpected errors", async () => {
(ApiClient as Mock).mockImplementation(() => ({
createOrUpdate: vi.fn().mockRejectedValue(new Error("Unexpected error")),
}));
(ApiClient as Mock).mockImplementation(function () {
return {
createOrUpdateUser: vi
.fn()
.mockRejectedValue(new Error("Unexpected error")),
};
});

const result = await sendUpdates({ updates: { userId: mockUserId, attributes: mockAttributes } });
const result = await sendUpdates({
updates: { userId: mockUserId, attributes: mockAttributes },
});

expect(result.ok).toBe(false);
if (!result.ok) {
Expand Down
5 changes: 3 additions & 2 deletions packages/react-native/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { resolve } from "node:path";
import { type UserConfig, defineConfig } from "vite";
import { defineConfig } from "vite";
import { ViteUserConfig } from "vitest/config";
import dts from "vite-plugin-dts";

const config = (): UserConfig => {
const config = (): ViteUserConfig => {
return defineConfig({
resolve: {
alias: {
Expand Down
Loading
Loading