UNPKG

mypa-google-docs-importer

Version:

Imports Google docs documents and saves them to JSON.

65 lines (57 loc) 1.42 kB
import { describe, it, expect } from "vitest"; import { formatRecords } from "./index"; import { createMockContext } from "./__tests__/createMockContext"; describe("formatRecords", () => { it("throws error when records can't be parsed", () => { const result = formatRecords( ["nl", "woord"], ["language", "my_translation"], null, createMockContext(), ); expect(result).toEqual({ key: "nl", records: { lang: "nl", my_translation: "woord", }, }); }); it("throws error when records are empty", () => { expect(() => { formatRecords([], ["a"], null, createMockContext()); }).toThrow(Error); }); it("adds a prefix to the keys", () => { const result = formatRecords( ["nl", "woord"], ["language", "my_translation"], null, createMockContext({ prefix: "sp_" }), ); expect(result).toEqual({ key: "nl", records: { lang: "nl", sp_my_translation: "woord", }, }); }); it("groups by namespace", () => { const result = formatRecords( ["nl", "woord"], ["language", "my_translation"], ["namespace", "my_namespace"], createMockContext(), ); expect(result).toEqual({ key: "nl", records: { my_namespace: { my_translation: "woord", }, lang: "nl", }, }); }); });