Skip to content

Commit

Permalink
Updated model tests to coform with our changes to remove the retrievi…
Browse files Browse the repository at this point in the history
…ng of repo data, and also fixed spelling error that caused a lint error
  • Loading branch information
brwali committed Nov 26, 2024
1 parent 99faa37 commit e690ca0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 174 deletions.
42 changes: 0 additions & 42 deletions app/models/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,6 @@ class Metric < ActiveRecord::Base
}
QUERY

REPO_QUERY = <<~QUERY
query {
repository(owner: "%<owner_name>s", name: "%<repository_name>s") {
ref(qualifiedName: "master") {
target {
... on Commit {
id
history(%<after_clause>s since: "%<start_date>s") {
edges {
node {
id author {
name email date
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}
}
QUERY

# Generate the GraphQL query text for a PULL REQUEST link.
#
# hyperlink_data - a hash containing the owner name, repository name, and pull request number.
Expand All @@ -68,19 +41,4 @@ def self.pull_query(hyperlink_data)
})
end

# Generate the GraphQL query text for a REPOSITORY link.
#
# hyperlink_data - a hash containing the owner name and repository name.
# date - the assignment start date, in the format "YYYY-MM-DD".
# after - a pointer provided by the Github API to where the last query left off.
#
# Returns a hash containing the query text.
def self.repo_query(hyperlink_data, date)
format(REPO_QUERY, {
owner_name: hyperlink_data["owner_name"],
repository_name: hyperlink_data["repository_name"],
start_date: date.iso8601(3),
after_clause: nil
})
end
end
2 changes: 1 addition & 1 deletion app/views/assignments/edit/_rubrics.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if (round_no == null && duty_id == undefined) {
html += '<td><label for="questionnaire_id">' + questionnaire.display_type + ':</label></td>';
} else if (round_no == null && duty_id != undefined) {
// E2147 : Add name of duty infront of the questionnaire type to select for which duty the questionnaire is being selected
// E2147 : Add name of duty in front of the questionnaire type to select for which duty the questionnaire is being selected
html += '<td><label for="questionnaire_id">' + questionnaire.display_type + ' Role ' + duty_name + ':</label></td>';
}
else if (round_no!=null && duty_id == undefined) {
Expand Down
14 changes: 0 additions & 14 deletions spec/models/assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -726,19 +726,5 @@ def generated_csv(t_assignment, t_options)
end
end
end
describe '#uses_github?' do

it 'does NOT use github' do
create(:assignment)
create(:assignment_team, name: 'team1', submitted_hyperlinks: ["https://expertiza.ncsu.edu/"])
expect(assignment.uses_github?).to eq(false)
end

it 'uses github' do
create(:assignment)
create(:assignment_team, name: 'team1', submitted_hyperlinks: ["https://www.github.com/anonymous/expertiza", "https://github.com/expertiza/expertiza/pull/1234"])
expect(assignment.uses_github?).to eq(true)
end
end
end

137 changes: 20 additions & 117 deletions spec/models/metric_spec.rb
Original file line number Diff line number Diff line change
@@ -1,136 +1,39 @@
describe Metric do

describe 'pull_query' do
it 'constructs the query for the first page' do
query = {
query: "query {
repository(owner: \"expertiza\", name:\"expertiza\") {
pullRequest(number: 1228) {
number additions deletions changedFiles mergeable merged headRefOid
commits(first:100 ){
totalCount
pageInfo{
hasNextPage startCursor endCursor
}
edges{
node{
id commit{
author{
name email
}
additions deletions changedFiles committedDate
}}}}}}}"
}
hyperlink_data = {}
hyperlink_data["owner_name"] = "expertiza"
hyperlink_data["repository_name"] = "expertiza"
hyperlink_data["pull_request_number"] = "1228"
response = Metric.pull_query(hyperlink_data, nil)
expect(response).to eq(query)
end

it 'constructs the query for additional pages after 100 commits' do
query = {
query: "query {
repository(owner: \"expertiza\", name:\"expertiza\") {
pullRequest(number: 1228) {
number additions deletions changedFiles mergeable merged headRefOid
commits(first:100 after:\"pointer\"){
totalCount
pageInfo{
hasNextPage startCursor endCursor
}
edges{
node{
id commit{
author{
name email
}
additions deletions changedFiles committedDate
}}}}}}}"
}
hyperlink_data = {}
hyperlink_data["owner_name"] = "expertiza"
hyperlink_data["repository_name"] = "expertiza"
hyperlink_data["pull_request_number"] = "1228"
after="pointer" # In production, this will be a github SHA1 hash
response = Metric.pull_query(hyperlink_data, after)
expect(response).to eq(query)
end
end

describe 'repo_query' do
it 'constructs the query for the first page' do
date = DateTime.yesterday
query = {
query: "query {
repository(owner: \"expertiza\", name: \"expertiza\") {
ref(qualifiedName: \"master\") {
target {
... on Commit {
id
history( since:\"#{date.to_time.iso8601.to_s[0..18]}\") {
edges {
node {
id author {
name email date
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
repository(owner: \"expertiza\", name: \"expertiza\") {
pullRequest(number: 1228) {
number additions deletions changedFiles mergeable merged headRefOid
commits(first: 100 ) {
totalCount
pageInfo {
hasNextPage startCursor endCursor
}
}"
}
hyperlink_data = {}
hyperlink_data["owner_name"] = "expertiza"
hyperlink_data["repository_name"] = "expertiza"
response = Metric.repo_query(hyperlink_data, date, nil)
expect(response).to eq(query)
end

it 'constructs the query for additional pages after 100 commits' do
date = DateTime.yesterday
query = {
query: "query {
repository(owner: \"expertiza\", name: \"expertiza\") {
ref(qualifiedName: \"master\") {
target {
... on Commit {
id
history(after:\"pointer\" since:\"#{date.to_time.iso8601.to_s[0..18]}\") {
edges {
node {
id author {
name email date
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
edges {
node {
id commit {
author {
name email
}
additions deletions changedFiles committedDate
}
}
}
}"
}
}
}
}"
}
hyperlink_data = {}
hyperlink_data["owner_name"] = "expertiza"
hyperlink_data["repository_name"] = "expertiza"
hyperlink_data["pull_request_number"] = "1228"
after="pointer" # In production, this will be a github SHA1 hash
response = Metric.repo_query(hyperlink_data, date, after)
expect(response).to eq(query)
response = Metric.pull_query(hyperlink_data)
expect(response.strip).to eq(query[:query])
end
end

end
end

0 comments on commit e690ca0

Please sign in to comment.