This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(screenview): missing config hit (#191)
closes #178
- Loading branch information
1 parent
efce686
commit 0223f52
Showing
9 changed files
with
85 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import pageview from "@/api/pageview"; | ||
import config from "@/api/config"; | ||
import event from "@/api/event"; | ||
|
||
jest.mock("@/api/config"); | ||
jest.mock("@/api/event"); | ||
|
||
describe("api/pageview", () => { | ||
it("should be called with this parameters", () => { | ||
pageview("foo"); | ||
expect(config).toHaveBeenCalledWith({ | ||
|
||
expect(event).toHaveBeenCalledWith("page_view", { | ||
page_path: "foo", | ||
page_location: "http://localhost/", | ||
send_page_view: true, | ||
}); | ||
|
||
pageview({ foo: "bar" }); | ||
expect(config).toHaveBeenCalledWith({ foo: "bar" }); | ||
|
||
expect(event).toHaveBeenCalledWith("page_view", { | ||
foo: "bar", | ||
send_page_view: true, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
import { getOptions } from "@/install"; | ||
import screenview from "@/api/screenview"; | ||
import event from "@/api/event"; | ||
|
||
jest.mock("@/api/event"); | ||
jest.mock("@/install"); | ||
|
||
describe("api/screenview", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should be called with this parameters", () => { | ||
screenview("foo"); | ||
expect(event).toHaveBeenCalledWith("screen_view", "foo"); | ||
getOptions.mockReturnValue({ | ||
config: { id: 1 }, | ||
appName: "MyApp", | ||
}); | ||
|
||
screenview("bar"); | ||
|
||
expect(event).toHaveBeenCalledWith("screen_view", { | ||
send_page_view: true, | ||
screen_name: "bar", | ||
app_name: "MyApp", | ||
}); | ||
|
||
screenview({ foo: "bar" }); | ||
expect(event).toHaveBeenCalledWith("screen_view", { foo: "bar" }); | ||
|
||
expect(event).toHaveBeenCalledWith("screen_view", { | ||
send_page_view: true, | ||
foo: "bar", | ||
app_name: "MyApp", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
import { getOptions } from "../install"; | ||
import event from "./event"; | ||
|
||
export default (...args) => { | ||
event("screen_view", ...args); | ||
const { appName } = getOptions(); | ||
const [arg] = args; | ||
let params = {}; | ||
|
||
if (typeof arg === "string") { | ||
params = { | ||
screen_name: arg, | ||
}; | ||
} else { | ||
params = arg; | ||
} | ||
|
||
if (params.app_name == null) { | ||
params.app_name = appName; | ||
} | ||
|
||
if (params.send_page_view == null) { | ||
params.send_page_view = true; | ||
} | ||
|
||
event("screen_view", params); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters