-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
65 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Represents the front page or home URL transmitted when making requests. | ||
export class Blog | ||
|
||
# Creates a new blog. | ||
constructor: (options = {}) -> | ||
|
||
# The character encoding for the values included in comments. | ||
@charset = options.charset ? "" | ||
|
||
# The languages in use on the blog or site, in ISO 639-1 format. | ||
@languages = new Set(options.languages ? []) | ||
|
||
# The blog or site URL. | ||
@url = if options.url then new URL options.url else null | ||
|
||
# Creates a new blog from the specified JSON object. | ||
@fromJson: (json) -> new @ | ||
charset: if typeof json.blog_charset == "string" then json.blog_charset else "" | ||
languages: if typeof json.blog_lang == "string" then json.blog_lang.split(",").map (language) -> language.trim() else [] | ||
url: if typeof json.blog == "string" then json.blog else "" | ||
|
||
# Returns a JSON representation of this object. | ||
toJSON: -> | ||
map = blog: @url?.href ? "" | ||
map.blog_charset = @charset if @charset | ||
map.blog_lang = Array.from(@languages).join "," if @languages.size | ||
map |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {Blog} from "@cedx/akismet" | ||
import {deepEqual, equal, ok} from "node:assert/strict" | ||
import {describe, it} from "node:test" | ||
|
||
# Tests the features of the `Blog` class. | ||
describe "Blog", -> | ||
describe "fromJson()", -> | ||
it "should return an empty instance with an empty map", -> | ||
blog = Blog.fromJson {} | ||
equal blog.charset.length, 0 | ||
equal blog.languages.length, 0 | ||
equal blog.url, null | ||
|
||
it "should return an initialized instance with a non-empty map", -> | ||
blog = Blog.fromJson | ||
blog: "https://github.com/cedx/akismet.js" | ||
blog_charset: "UTF-8" | ||
blog_lang: "en, fr" | ||
|
||
equal blog.charset, "UTF-8" | ||
deepEqual blog.languages, ["en", "fr"] | ||
ok blog.url instanceof URL | ||
equal blog.url.href, "https://github.com/cedx/akismet.js" | ||
|
||
describe "toJSON()", -> | ||
it "should return only the blog URL with a newly created instance", -> | ||
json = new Blog(url: "https://github.com/cedx/akismet.js").toJSON() | ||
equal Object.keys(json).length, 1 | ||
equal json.blog, "https://github.com/cedx/akismet.js" | ||
|
||
it "should return a non-empty map with an initialized instance", -> | ||
json = new Blog(charset: "UTF-8", languages: ["en", "fr"], url: "https://github.com/cedx/akismet.js").toJSON() | ||
equal Object.keys(json).length, 3 | ||
equal json.blog, "https://github.com/cedx/akismet.js" | ||
equal json.blog_charset, "UTF-8" | ||
equal json.blog_lang, "en,fr" |
This file was deleted.
Oops, something went wrong.