Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow duplication options #309

Merged
merged 7 commits into from
Apr 23, 2024
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
1 change: 1 addition & 0 deletions deployment/after-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ services:
SENTRY_SAMPLE_RATE: ${SENTRY_SAMPLE_RATE:-1}
CLOUDFRONT_KEY_ID: ${CLOUDFRONT_KEY_ID}
JOTFORM_APIKEY: ${JOTFORM_APIKEY}
WORDPRESS_API_URL: ${WORDPRESS_API_URL}
volumes:
- /var/docker/keys:/app/keys
logging:
Expand Down
96 changes: 96 additions & 0 deletions src/features/wp/WordpressJsonApiTrigger/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import axios from "axios";
import WordpressJsonApiTrigger from ".";

// mock axios

jest.mock("axios");

describe("WordpressJsonApiTrigger", () => {
beforeAll(() => {
process.env = Object.assign(process.env, {
WORDPRESS_API_URL: "https://example.com",
});
});

afterAll(() => {
jest.resetAllMocks();
process.env = Object.assign(process.env, {
WORDPRESS_API_URL: "",
});
});

afterEach(() => {
jest.clearAllMocks();
});
it("Should create a new instance of WordpressJsonApiTrigger", () => {
const instance = new WordpressJsonApiTrigger(1);
expect(instance).toBeInstanceOf(WordpressJsonApiTrigger);
});

it("Should call axios on generateUseCase", async () => {
const instance = new WordpressJsonApiTrigger(1);

await instance.generateUseCase();

expect(axios).toHaveBeenCalledTimes(1);

expect(axios).toHaveBeenCalledWith({
headers: {
"Content-Type": "application/json",
"User-Agent": "Tryber API",
},
method: "GET",
url: "https://example.com/regenerate-campaign-use-cases/1",
});
});

it("Should call axios on generateMailmerges", async () => {
const instance = new WordpressJsonApiTrigger(1);

await instance.generateMailMerges();

expect(axios).toHaveBeenCalledTimes(1);

expect(axios).toHaveBeenCalledWith({
headers: {
"Content-Type": "application/json",
"User-Agent": "Tryber API",
},
method: "GET",
url: "https://example.com/regenerate-campaign-crons/1",
});
});
it("Should call axios on generatePages", async () => {
const instance = new WordpressJsonApiTrigger(1);

await instance.generatePages();

expect(axios).toHaveBeenCalledTimes(1);

expect(axios).toHaveBeenCalledWith({
headers: {
"Content-Type": "application/json",
"User-Agent": "Tryber API",
},
method: "GET",
url: "https://example.com/regenerate-campaign-pages/1",
});
});

it("Should call axios on generateTasks", async () => {
const instance = new WordpressJsonApiTrigger(1);

await instance.generateTasks();

expect(axios).toHaveBeenCalledTimes(1);

expect(axios).toHaveBeenCalledWith({
headers: {
"Content-Type": "application/json",
"User-Agent": "Tryber API",
},
method: "GET",
url: "https://example.com/regenerate-campaign-tasks/1",
});
});
});
36 changes: 36 additions & 0 deletions src/features/wp/WordpressJsonApiTrigger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import axios from "axios";

class WordpressJsonApiTrigger {
constructor(private campaign: number) {}

public async generateUseCase() {
await this.postToWordpress(
`regenerate-campaign-use-cases/${this.campaign}`
);
}

public async generateMailMerges() {
await this.postToWordpress(`regenerate-campaign-crons/${this.campaign}`);
}

public async generatePages() {
await this.postToWordpress(`regenerate-campaign-pages/${this.campaign}`);
}

public async generateTasks() {
await this.postToWordpress(`regenerate-campaign-tasks/${this.campaign}`);
}

private async postToWordpress(url: string) {
await axios({
method: "GET",
url: `${process.env.WORDPRESS_API_URL}/${url}`,
headers: {
"User-Agent": "Tryber API",
"Content-Type": "application/json",
},
});
}
}

export default WordpressJsonApiTrigger;
Loading
Loading