-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/episode-create-delete
- Loading branch information
Showing
14 changed files
with
277 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import json | ||
from graphene_django.utils.testing import GraphQLTestCase | ||
|
||
from event.models import Episode | ||
from source.models import Source | ||
from user.models import User | ||
|
||
|
||
class ContributorTestCase(GraphQLTestCase): | ||
GRAPHQL_URL = "/api/graphql" | ||
|
||
# Any mutation involving a model that inherits EntityDescription will do. | ||
# For these tests, we'll use the Episode model. | ||
|
||
UPDATE_EPISODE_MUTATION = """ | ||
mutation UPDATE_EPISODE($input: UpdateEpisodeMutationInput!) { | ||
updateEpisode(input: $input) { | ||
ok | ||
errors { | ||
field | ||
messages | ||
} | ||
} | ||
} | ||
""" | ||
|
||
@classmethod | ||
def setUpTestData(cls) -> None: | ||
source = Source.objects.create(name="A New Hope") | ||
cls.episode = Episode.objects.create( | ||
name="Death Star destroyed", source_id=source.pk | ||
) | ||
cls.user_1 = User.objects.create(username="Yoda") | ||
cls.user_2 = User.objects.create(username="Obi-Wan") | ||
|
||
def test_single_contributor_one_contribution(self): | ||
self.client.force_login(self.user_1) | ||
|
||
response = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Palpatine"}, | ||
) | ||
self.assertResponseNoErrors(response) | ||
|
||
episode = Episode.objects.get(id=self.episode.pk) | ||
|
||
first_contributor = episode.contributors.first() | ||
|
||
if not first_contributor: | ||
self.fail("No contributors found after mutation.") | ||
|
||
self.assertEqual(first_contributor.username, "Yoda") | ||
|
||
def test_one_contributor_multiple_contributions(self): | ||
self.client.force_login(self.user_1) | ||
|
||
response = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Palpatine"}, | ||
) | ||
self.assertResponseNoErrors(response) | ||
|
||
response = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Darth Vader"}, | ||
) | ||
self.assertResponseNoErrors(response) | ||
|
||
episode = Episode.objects.get(id=self.episode.pk) | ||
|
||
self.assertEqual( | ||
len(episode.contributors.all()), | ||
1, | ||
"Contributors should not increase after multiple contributions.", | ||
) | ||
|
||
def test_multiple_contributors_one_contribution(self): | ||
self.client.force_login(self.user_1) | ||
response = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Han"}, | ||
) | ||
self.assertResponseNoErrors(response) | ||
|
||
self.client.force_login(self.user_2) | ||
response = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Leia"}, | ||
) | ||
self.assertResponseNoErrors(response) | ||
|
||
episode = Episode.objects.get(id=self.episode.pk) | ||
|
||
first_contributor = episode.contributors.first() | ||
second_contributor = episode.contributors.last() | ||
|
||
if not first_contributor or not second_contributor: | ||
self.fail("No contributors found after mutation.") | ||
|
||
self.assertEqual(first_contributor.username, "Yoda") | ||
self.assertEqual(second_contributor.username, "Obi-Wan") | ||
|
||
def test_multiple_contributors_multiple_contributions(self): | ||
self.client.force_login(self.user_1) | ||
response_1_1 = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Jabba"}, | ||
) | ||
response_1_2 = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Anakin"}, | ||
) | ||
|
||
self.client.force_login(self.user_2) | ||
response_2_1 = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Jango"}, | ||
) | ||
response_2_2 = self.query( | ||
query=self.UPDATE_EPISODE_MUTATION, | ||
input_data={"id": self.episode.pk, "name": "Boba"}, | ||
) | ||
|
||
self.assertResponseNoErrors(response_1_1) | ||
self.assertResponseNoErrors(response_1_2) | ||
self.assertResponseNoErrors(response_2_1) | ||
self.assertResponseNoErrors(response_2_2) | ||
|
||
episode = Episode.objects.get(id=self.episode.pk) | ||
|
||
first_contributor = episode.contributors.first() | ||
second_contributor = episode.contributors.last() | ||
|
||
if not first_contributor or not second_contributor: | ||
self.fail("No contributors found after mutation.") | ||
|
||
self.assertEqual(first_contributor.username, "Yoda") | ||
self.assertEqual(second_contributor.username, "Obi-Wan") |
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
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
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
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
8 changes: 8 additions & 0 deletions
8
frontend/src/app/shared/contributors/contributors.component.html
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,8 @@ | ||
<small class="contributors text-muted"> | ||
<ng-container *ngIf="contributors.length === 0" | ||
>No contributors</ng-container | ||
> | ||
<ng-container *ngIf="contributors.length === 1">Contributor: {{ contributors[0].fullName }}</ng-container> | ||
<ng-container *ngIf="contributors.length === 2">Contributors: {{ contributors[0].fullName }}, {{ contributors[1].fullName }}</ng-container> | ||
<ng-container *ngIf="contributors.length > 2">Contributors: {{ contributors[0].fullName }} et al.</ng-container> | ||
</small> |
Empty file.
74 changes: 74 additions & 0 deletions
74
frontend/src/app/shared/contributors/contributors.component.spec.ts
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,74 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
import { ContributorsComponent } from "./contributors.component"; | ||
import { UserType } from "generated/graphql"; | ||
|
||
describe("ContributorsComponent", () => { | ||
let component: ContributorsComponent; | ||
let fixture: ComponentFixture<ContributorsComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ContributorsComponent], | ||
}); | ||
fixture = TestBed.createComponent(ContributorsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it("should have input property 'contributors'", () => { | ||
expect(component.contributors).toBeDefined(); | ||
}); | ||
|
||
it("should render no contributors", () => { | ||
const contributors: Pick<UserType, "id" | "fullName">[] = []; | ||
component.contributors = contributors; | ||
fixture.detectChanges(); | ||
const compiled = fixture.nativeElement; | ||
const element: HTMLElement = compiled.querySelector(".contributors"); | ||
self.expect(element).toBeDefined(); | ||
self.expect(element.textContent).toBe("No contributors"); | ||
}); | ||
|
||
it("should render one contributor", () => { | ||
const contributors: Pick<UserType, "id" | "fullName">[] = [ | ||
{ id: "1", fullName: "Anakin Skywalker" }, | ||
]; | ||
component.contributors = contributors; | ||
fixture.detectChanges(); | ||
const compiled = fixture.nativeElement; | ||
const element: HTMLElement = compiled.querySelector(".contributors"); | ||
self.expect(element).toBeDefined(); | ||
self.expect(element.textContent).toBe("Contributor: Anakin Skywalker"); | ||
}); | ||
|
||
it("should render two contributors", () => { | ||
const contributors: Pick<UserType, "id" | "fullName">[] = [ | ||
{ id: "1", fullName: "Anakin Skywalker" }, | ||
{ id: "2", fullName: "Jabba the Hutt" }, | ||
]; | ||
component.contributors = contributors; | ||
fixture.detectChanges(); | ||
const compiled = fixture.nativeElement; | ||
const element: HTMLElement = compiled.querySelector(".contributors"); | ||
self.expect(element).toBeDefined(); | ||
self.expect(element.textContent).toBe("Contributors: Anakin Skywalker, Jabba the Hutt"); | ||
}); | ||
|
||
it("should render three contributors", () => { | ||
const contributors: Pick<UserType, "id" | "fullName">[] = [ | ||
{ id: "1", fullName: "Anakin Skywalker" }, | ||
{ id: "2", fullName: "Jabba the Hutt" }, | ||
{ id: "3", fullName: "Queen Amidala" }, | ||
]; | ||
component.contributors = contributors; | ||
fixture.detectChanges(); | ||
const compiled = fixture.nativeElement; | ||
const element: HTMLElement = compiled.querySelector(".contributors"); | ||
self.expect(element).toBeDefined(); | ||
self.expect(element.textContent).toBe("Contributors: Anakin Skywalker et al."); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
frontend/src/app/shared/contributors/contributors.component.ts
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,12 @@ | ||
import { Component, Input } from "@angular/core"; | ||
import { UserType } from "generated/graphql"; | ||
|
||
@Component({ | ||
selector: "lc-contributors", | ||
templateUrl: "./contributors.component.html", | ||
styleUrls: ["./contributors.component.scss"], | ||
}) | ||
export class ContributorsComponent { | ||
@Input({ required: true }) | ||
public contributors: Pick<UserType, "id" | "fullName">[] = []; | ||
} |
Oops, something went wrong.