Skip to content

Commit

Permalink
build(test): update cdn links
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao authored Jan 10, 2025
1 parent 8139d2b commit 46a10c2
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 116 deletions.
92 changes: 46 additions & 46 deletions test/01_standardParsing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,64 @@ import { expect } from 'chai';
import { loadEPUB } from '../dist/node/index.js';

const list = JSON.parse(await fs.promises.readFile(new URL('./standardParsing/list.json', import.meta.url)));
const JW_CDN = 'https://app.jw-cdn.org/apis/pub-media/GETPUBMEDIALINKS?';
const JW_CDN = 'https://b.jw-cdn.org/apis/pub-media/GETPUBMEDIALINKS?';

const fetchData = async (language, issue, pub) => {
let data = [];
let fixture = [];
let data = [];
let fixture = [];

const url =
JW_CDN +
new URLSearchParams({
langwritten: language,
pub,
fileformat: 'epub',
output: 'json',
issue,
});
const url =
JW_CDN +
new URLSearchParams({
langwritten: language,
pub,
fileformat: 'epub',
output: 'json',
issue,
});

const res = await fetch(url);
const res = await fetch(url);

if (res.status === 200) {
const result = await res.json();
const epubEntry = result.files[language].EPUB;
if (res.status === 200) {
const result = await res.json();
const epubEntry = result.files[language].EPUB;

const epubFile = epubEntry[0].file;
const epubUrl = epubFile.url;
const epubName = path.basename(epubUrl);
data = await loadEPUB({ url: epubUrl });
fixture = (await import(`./fixtures/${epubName.replace('.epub', '.js')}`)).default;
}
const epubFile = epubEntry[0].file;
const epubUrl = epubFile.url;
const epubName = path.basename(epubUrl);
data = await loadEPUB({ url: epubUrl });
fixture = (await import(`./fixtures/${epubName.replace('.epub', '.js')}`)).default;
}

return { data, fixture };
return { data, fixture };
};

describe('Testing Standard Parsing', () => {
for (let i = 0; i < list.length; i++) {
const { language, issue } = list[i];
for (let i = 0; i < list.length; i++) {
const { language, issue } = list[i];

describe(`Test loadEPUB function for ${language} language`, async () => {
it(`Parsing Meeting Workbook EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'mwb');
describe(`Test loadEPUB function for ${language} language`, async () => {
it(`Parsing Meeting Workbook EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'mwb');

for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});
for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});

it(`Parsing Watchtower Study EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'w');
it(`Parsing Watchtower Study EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'w');

for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});
});
}
for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});
});
}
});
140 changes: 70 additions & 70 deletions test/02_enhancedParsing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,90 @@ import { loadEPUB } from '../dist/node/index.js';

const list = JSON.parse(await fs.promises.readFile(new URL('./enhancedParsing/list.json', import.meta.url)));

const JW_CDN = 'https://app.jw-cdn.org/apis/pub-media/GETPUBMEDIALINKS?';
const JW_CDN = 'https://b.jw-cdn.org/apis/pub-media/GETPUBMEDIALINKS?';

const fetchIssueData = async (issue, pub) => {
try {
if (issue.hasEPUB) {
const epubFile = issue.hasEPUB[0].file;
const epubUrl = epubFile.url;

const epubData = await loadEPUB({ url: epubUrl });
return epubData;
}

if (!issue.hasEPUB) {
return [];
}
} catch (err) {
throw new Error(err);
}
try {
if (issue.hasEPUB) {
const epubFile = issue.hasEPUB[0].file;
const epubUrl = epubFile.url;

const epubData = await loadEPUB({ url: epubUrl });
return epubData;
}

if (!issue.hasEPUB) {
return [];
}
} catch (err) {
throw new Error(err);
}
};

const fetchData = async (language, issue, pub) => {
let data = [];
let fixture = [];
let data = [];
let fixture = [];

const url =
JW_CDN +
new URLSearchParams({
langwritten: language,
pub,
output: 'json',
issue,
});
const url =
JW_CDN +
new URLSearchParams({
langwritten: language,
pub,
output: 'json',
issue,
});

const res = await fetch(url);
const res = await fetch(url);

if (res.status === 200) {
const result = await res.json();
const hasEPUB = result.files[language].EPUB;
if (res.status === 200) {
const result = await res.json();
const hasEPUB = result.files[language].EPUB;

const issueFetch = { issueDate: issue, currentYear: issue.substring(0, 4), language, hasEPUB: hasEPUB };
const issueFetch = { issueDate: issue, currentYear: issue.substring(0, 4), language, hasEPUB: hasEPUB };

data = await fetchIssueData(issueFetch, pub);
data = await fetchIssueData(issueFetch, pub);

if (hasEPUB) {
const epubFile = hasEPUB[0].file;
const epubUrl = epubFile.url;
const epubName = path.basename(epubUrl);
fixture = (await import(`./fixtures/${epubName.replace('.epub', '.js')}`)).default;
}
if (hasEPUB) {
const epubFile = hasEPUB[0].file;
const epubUrl = epubFile.url;
const epubName = path.basename(epubUrl);
fixture = (await import(`./fixtures/${epubName.replace('.epub', '.js')}`)).default;
}

if (!hasEPUB) {
fixture = (await import(`./fixtures/${pub}_${language}_${issue}.js`)).default;
}
}
if (!hasEPUB) {
fixture = (await import(`./fixtures/${pub}_${language}_${issue}.js`)).default;
}
}

return { data, fixture };
return { data, fixture };
};

describe('Testing Enhanced Parsing', async () => {
for (let i = 0; i < list.length; i++) {
const { language, issue } = list[i];

describe(`Test loadEPUB function for ${language} language`, async () => {
it(`Parsing Meeting Workbook EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'mwb');

for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});

it(`Parsing Watchtower Study EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'w');

for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});
});
}
for (let i = 0; i < list.length; i++) {
const { language, issue } = list[i];

describe(`Test loadEPUB function for ${language} language`, async () => {
it(`Parsing Meeting Workbook EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'mwb');

for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});

it(`Parsing Watchtower Study EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'w');

for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});
});
}
});

0 comments on commit 46a10c2

Please sign in to comment.