mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:41:25 +08:00
DEV: Apply syntax_tree formatting to script/*
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
BASES = '{
|
||||
# frozen_string_literal: true
|
||||
BASES =
|
||||
'{
|
||||
"type" : "kbase",
|
||||
"data" : [ {
|
||||
"objectId" : "90b1ccf3-35aa-4d6f-848e-e7c122d92c58",
|
||||
@ -9,7 +10,8 @@
|
||||
} ]
|
||||
}'
|
||||
|
||||
QUESTIONS = '{
|
||||
QUESTIONS =
|
||||
'{
|
||||
"type": "question-search-result",
|
||||
"data": {
|
||||
"totalSize": 445,
|
||||
@ -50,7 +52,8 @@
|
||||
}
|
||||
}'
|
||||
|
||||
QUESTION = '{
|
||||
QUESTION =
|
||||
'{
|
||||
"type" : "question",
|
||||
"data" : {
|
||||
"uid" : "de20ed0a-5fe5-48a5-9c14-d854f9af99f1",
|
||||
|
@ -1,21 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'yaml'
|
||||
require_relative '../quandora_api.rb'
|
||||
require_relative './test_data.rb'
|
||||
require "minitest/autorun"
|
||||
require "yaml"
|
||||
require_relative "../quandora_api.rb"
|
||||
require_relative "./test_data.rb"
|
||||
|
||||
class TestQuandoraApi < Minitest::Test
|
||||
|
||||
DEBUG = false
|
||||
|
||||
def initialize(args)
|
||||
config = YAML::load_file(File.join(__dir__, 'config.yml'))
|
||||
@domain = config['domain']
|
||||
@username = config['username']
|
||||
@password = config['password']
|
||||
@kb_id = config['kb_id']
|
||||
@question_id = config['question_id']
|
||||
config = YAML.load_file(File.join(__dir__, "config.yml"))
|
||||
@domain = config["domain"]
|
||||
@username = config["username"]
|
||||
@password = config["password"]
|
||||
@kb_id = config["kb_id"]
|
||||
@question_id = config["question_id"]
|
||||
super args
|
||||
end
|
||||
|
||||
@ -30,19 +29,19 @@ class TestQuandoraApi < Minitest::Test
|
||||
end
|
||||
|
||||
def test_base_url
|
||||
assert_equal 'https://mydomain.quandora.com/m/json', @quandora.base_url('mydomain')
|
||||
assert_equal "https://mydomain.quandora.com/m/json", @quandora.base_url("mydomain")
|
||||
end
|
||||
|
||||
def test_auth_header
|
||||
user = 'Aladdin'
|
||||
password = 'open sesame'
|
||||
user = "Aladdin"
|
||||
password = "open sesame"
|
||||
auth_header = @quandora.auth_header user, password
|
||||
assert_equal 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', auth_header[:Authorization]
|
||||
assert_equal "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", auth_header[:Authorization]
|
||||
end
|
||||
|
||||
def test_list_bases_element_has_expected_structure
|
||||
element = @quandora.list_bases[0]
|
||||
expected = JSON.parse(BASES)['data'][0]
|
||||
expected = JSON.parse(BASES)["data"][0]
|
||||
debug element
|
||||
check_keys expected, element
|
||||
end
|
||||
@ -50,24 +49,24 @@ class TestQuandoraApi < Minitest::Test
|
||||
def test_list_questions_has_expected_structure
|
||||
response = @quandora.list_questions @kb_id, 1
|
||||
debug response
|
||||
check_keys JSON.parse(QUESTIONS)['data']['result'][0], response[0]
|
||||
check_keys JSON.parse(QUESTIONS)["data"]["result"][0], response[0]
|
||||
end
|
||||
|
||||
def test_get_question_has_expected_structure
|
||||
question = @quandora.get_question @question_id
|
||||
expected = JSON.parse(QUESTION)['data']
|
||||
expected = JSON.parse(QUESTION)["data"]
|
||||
check_keys expected, question
|
||||
|
||||
expected_comment = expected['comments'][0]
|
||||
actual_comment = question['comments'][0]
|
||||
expected_comment = expected["comments"][0]
|
||||
actual_comment = question["comments"][0]
|
||||
check_keys expected_comment, actual_comment
|
||||
|
||||
expected_answer = expected['answersList'][1]
|
||||
actual_answer = question['answersList'][0]
|
||||
expected_answer = expected["answersList"][1]
|
||||
actual_answer = question["answersList"][0]
|
||||
check_keys expected_answer, actual_answer
|
||||
|
||||
expected_answer_comment = expected_answer['comments'][0]
|
||||
actual_answer_comment = actual_answer['comments'][0]
|
||||
expected_answer_comment = expected_answer["comments"][0]
|
||||
actual_answer_comment = actual_answer["comments"][0]
|
||||
check_keys expected_answer_comment, actual_answer_comment
|
||||
end
|
||||
|
||||
@ -75,18 +74,16 @@ class TestQuandoraApi < Minitest::Test
|
||||
|
||||
def check_keys(expected, actual)
|
||||
msg = "### caller[0]:\nKey not found in actual keys: #{actual.keys}\n"
|
||||
expected.keys.each do |k|
|
||||
assert (actual.keys.include? k), "#{k}"
|
||||
end
|
||||
expected.keys.each { |k| assert (actual.keys.include? k), "#{k}" }
|
||||
end
|
||||
|
||||
def debug(message, show = false)
|
||||
if show || DEBUG
|
||||
puts '### ' + caller[0]
|
||||
puts ''
|
||||
puts "### " + caller[0]
|
||||
puts ""
|
||||
puts message
|
||||
puts ''
|
||||
puts ''
|
||||
puts ""
|
||||
puts ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,47 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'cgi'
|
||||
require 'time'
|
||||
require_relative '../quandora_question.rb'
|
||||
require_relative './test_data.rb'
|
||||
require "minitest/autorun"
|
||||
require "cgi"
|
||||
require "time"
|
||||
require_relative "../quandora_question.rb"
|
||||
require_relative "./test_data.rb"
|
||||
|
||||
class TestQuandoraQuestion < Minitest::Test
|
||||
|
||||
def setup
|
||||
@data = JSON.parse(QUESTION)['data']
|
||||
@data = JSON.parse(QUESTION)["data"]
|
||||
@question = QuandoraQuestion.new @data.to_json
|
||||
end
|
||||
|
||||
def test_topic
|
||||
topic = @question.topic
|
||||
assert_equal @data['uid'], topic[:id]
|
||||
assert_equal @data['author']['uid'], topic[:author_id]
|
||||
assert_equal unescape(@data['title']), topic[:title]
|
||||
assert_equal unescape(@data['content']), topic[:raw]
|
||||
assert_equal Time.parse(@data['created']), topic[:created_at]
|
||||
assert_equal @data["uid"], topic[:id]
|
||||
assert_equal @data["author"]["uid"], topic[:author_id]
|
||||
assert_equal unescape(@data["title"]), topic[:title]
|
||||
assert_equal unescape(@data["content"]), topic[:raw]
|
||||
assert_equal Time.parse(@data["created"]), topic[:created_at]
|
||||
end
|
||||
|
||||
def test_user_from_author
|
||||
author = {}
|
||||
author['uid'] = 'uid'
|
||||
author['firstName'] = 'Joe'
|
||||
author['lastName'] = 'Schmoe'
|
||||
author['email'] = 'joe.schmoe@mydomain.com'
|
||||
author["uid"] = "uid"
|
||||
author["firstName"] = "Joe"
|
||||
author["lastName"] = "Schmoe"
|
||||
author["email"] = "joe.schmoe@mydomain.com"
|
||||
|
||||
user = @question.user_from_author author
|
||||
|
||||
assert_equal 'uid', user[:id]
|
||||
assert_equal 'Joe Schmoe', user[:name]
|
||||
assert_equal 'joe.schmoe@mydomain.com', user[:email]
|
||||
assert_equal "uid", user[:id]
|
||||
assert_equal "Joe Schmoe", user[:name]
|
||||
assert_equal "joe.schmoe@mydomain.com", user[:email]
|
||||
assert_equal true, user[:staged]
|
||||
end
|
||||
|
||||
def test_user_from_author_with_no_email
|
||||
author = {}
|
||||
author['uid'] = 'foo'
|
||||
author["uid"] = "foo"
|
||||
user = @question.user_from_author author
|
||||
assert_equal 'foo@noemail.com', user[:email]
|
||||
assert_equal "foo@noemail.com", user[:email]
|
||||
end
|
||||
|
||||
def test_replies
|
||||
@ -57,77 +56,77 @@ class TestQuandoraQuestion < Minitest::Test
|
||||
assert_equal nil, replies[2][:reply_to_post_number]
|
||||
assert_equal 4, replies[3][:reply_to_post_number]
|
||||
assert_equal 3, replies[4][:reply_to_post_number]
|
||||
assert_equal '2013-01-07 04:59:56 UTC', replies[0][:created_at].to_s
|
||||
assert_equal '2013-01-08 16:49:32 UTC', replies[1][:created_at].to_s
|
||||
assert_equal '2016-01-20 15:38:55 UTC', replies[2][:created_at].to_s
|
||||
assert_equal '2016-01-21 15:38:55 UTC', replies[3][:created_at].to_s
|
||||
assert_equal '2016-01-22 15:38:55 UTC', replies[4][:created_at].to_s
|
||||
assert_equal "2013-01-07 04:59:56 UTC", replies[0][:created_at].to_s
|
||||
assert_equal "2013-01-08 16:49:32 UTC", replies[1][:created_at].to_s
|
||||
assert_equal "2016-01-20 15:38:55 UTC", replies[2][:created_at].to_s
|
||||
assert_equal "2016-01-21 15:38:55 UTC", replies[3][:created_at].to_s
|
||||
assert_equal "2016-01-22 15:38:55 UTC", replies[4][:created_at].to_s
|
||||
end
|
||||
|
||||
def test_post_from_answer
|
||||
answer = {}
|
||||
answer['uid'] = 'uid'
|
||||
answer['content'] = 'content'
|
||||
answer['created'] = '2013-01-06T18:24:54.62Z'
|
||||
answer['author'] = { 'uid' => 'auid' }
|
||||
answer["uid"] = "uid"
|
||||
answer["content"] = "content"
|
||||
answer["created"] = "2013-01-06T18:24:54.62Z"
|
||||
answer["author"] = { "uid" => "auid" }
|
||||
|
||||
post = @question.post_from_answer answer
|
||||
|
||||
assert_equal 'uid', post[:id]
|
||||
assert_equal "uid", post[:id]
|
||||
assert_equal @question.topic[:id], post[:parent_id]
|
||||
assert_equal answer['author'], post[:author]
|
||||
assert_equal 'auid', post[:author_id]
|
||||
assert_equal 'content', post[:raw]
|
||||
assert_equal Time.parse('2013-01-06T18:24:54.62Z'), post[:created_at]
|
||||
assert_equal answer["author"], post[:author]
|
||||
assert_equal "auid", post[:author_id]
|
||||
assert_equal "content", post[:raw]
|
||||
assert_equal Time.parse("2013-01-06T18:24:54.62Z"), post[:created_at]
|
||||
end
|
||||
|
||||
def test_post_from_comment
|
||||
comment = {}
|
||||
comment['text'] = 'text'
|
||||
comment['created'] = '2013-01-06T18:24:54.62Z'
|
||||
comment['author'] = { 'uid' => 'auid' }
|
||||
parent = { 'uid' => 'parent-uid' }
|
||||
comment["text"] = "text"
|
||||
comment["created"] = "2013-01-06T18:24:54.62Z"
|
||||
comment["author"] = { "uid" => "auid" }
|
||||
parent = { "uid" => "parent-uid" }
|
||||
|
||||
post = @question.post_from_comment comment, 0, parent
|
||||
|
||||
assert_equal 'parent-uid-0', post[:id]
|
||||
assert_equal 'parent-uid', post[:parent_id]
|
||||
assert_equal comment['author'], post[:author]
|
||||
assert_equal 'auid', post[:author_id]
|
||||
assert_equal 'text', post[:raw]
|
||||
assert_equal Time.parse('2013-01-06T18:24:54.62Z'), post[:created_at]
|
||||
assert_equal "parent-uid-0", post[:id]
|
||||
assert_equal "parent-uid", post[:parent_id]
|
||||
assert_equal comment["author"], post[:author]
|
||||
assert_equal "auid", post[:author_id]
|
||||
assert_equal "text", post[:raw]
|
||||
assert_equal Time.parse("2013-01-06T18:24:54.62Z"), post[:created_at]
|
||||
end
|
||||
|
||||
def test_post_from_comment_uses_parent_created_if_necessary
|
||||
comment = {}
|
||||
comment['author'] = { 'uid' => 'auid' }
|
||||
parent = { 'created' => '2013-01-06T18:24:54.62Z' }
|
||||
comment["author"] = { "uid" => "auid" }
|
||||
parent = { "created" => "2013-01-06T18:24:54.62Z" }
|
||||
|
||||
post = @question.post_from_comment comment, 0, parent
|
||||
|
||||
assert_equal Time.parse('2013-01-06T18:24:54.62Z'), post[:created_at]
|
||||
assert_equal Time.parse("2013-01-06T18:24:54.62Z"), post[:created_at]
|
||||
end
|
||||
|
||||
def test_post_from_comment_uses_previous_comment_as_parent
|
||||
comment = {}
|
||||
comment['author'] = { 'uid' => 'auid' }
|
||||
parent = { 'uid' => 'parent-uid', 'created' => '2013-01-06T18:24:54.62Z' }
|
||||
comment["author"] = { "uid" => "auid" }
|
||||
parent = { "uid" => "parent-uid", "created" => "2013-01-06T18:24:54.62Z" }
|
||||
|
||||
post = @question.post_from_comment comment, 1, parent
|
||||
|
||||
assert_equal 'parent-uid-1', post[:id]
|
||||
assert_equal 'parent-uid-0', post[:parent_id]
|
||||
assert_equal Time.parse('2013-01-06T18:24:54.62Z'), post[:created_at]
|
||||
assert_equal "parent-uid-1", post[:id]
|
||||
assert_equal "parent-uid-0", post[:parent_id]
|
||||
assert_equal Time.parse("2013-01-06T18:24:54.62Z"), post[:created_at]
|
||||
end
|
||||
|
||||
def test_users
|
||||
users = @question.users
|
||||
assert_equal 5, users.size
|
||||
assert_equal 'Ida Inquisitive', users[0][:name]
|
||||
assert_equal 'Harry Helpful', users[1][:name]
|
||||
assert_equal 'Sam Smarty-Pants', users[2][:name]
|
||||
assert_equal 'Greta Greatful', users[3][:name]
|
||||
assert_equal 'Eddy Excited', users[4][:name]
|
||||
assert_equal "Ida Inquisitive", users[0][:name]
|
||||
assert_equal "Harry Helpful", users[1][:name]
|
||||
assert_equal "Sam Smarty-Pants", users[2][:name]
|
||||
assert_equal "Greta Greatful", users[3][:name]
|
||||
assert_equal "Eddy Excited", users[4][:name]
|
||||
end
|
||||
|
||||
private
|
||||
|
Reference in New Issue
Block a user