Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions profile/README.init.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
# 👋 Hello there!

## Our top repositories

{- repositories -}
3 changes: 3 additions & 0 deletions profile/deps.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
export * as asserts from "https://deno.land/std@0.136.0/testing/asserts.ts";
export * as sinon from "https://cdn.skypack.dev/sinon";
export { denock } from "https://deno.land/x/denock@0.2.0/mod.ts";
11 changes: 11 additions & 0 deletions profile/src/application/UpdateTopRepositories.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
import { CodeRepositoryRepository } from "../domain/CodeRepository/CodeRepositoryRepository.ts";

export class UpdateTopRepositories {
public constructor(
private readonly codeRepositoryRepository: CodeRepositoryRepository
) {}

public async execute(): Promise<void> {
await this.codeRepositoryRepository.getTopRepositories();
}
}
5 changes: 5 additions & 0 deletions profile/src/domain/CodeRepository/CodeRepository.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
export interface CodeRepository {
name: string;
url: string;
starCount: number;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
import { CodeRepository } from "./CodeRepository.ts";

export interface CodeRepositoryRepository {
getTopRepositories: () => Promise<CodeRepository[]>;
}
24 changes: 24 additions & 0 deletions profile/src/infrastructure/HttpCodeRepositoryRepository.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
import { CodeRepository } from "../domain/CodeRepository/CodeRepository.ts";
import { CodeRepositoryRepository } from "../domain/CodeRepository/CodeRepositoryRepository.ts";

export class HttpCodeRepositoryRepository implements CodeRepositoryRepository {
public async getTopRepositories(): Promise<CodeRepository[]> {
await fetch("https://api.github.com/graphql", {
method: "POST",
body: `{
organization(login: "streamdevs") {
repositories(first: 3, orderBy: {field: STARGAZERS, direction: DESC}) {
nodes {
name
stargazerCount
}
}
}
}
`,
headers: { "content-type": "application/json" },
});

return Promise.resolve([]);
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
import { asserts, denock } from "../../../deps.ts";
import { HttpCodeRepositoryRepository } from "../../../src/infrastructure/HttpCodeRepositoryRepository.ts";

Deno.test("HttpCodeRepositoryRepository", async (t) => {
await t.step("it calls the GitHub API", async () => {
const scope = denock({
method: "POST",
protocol: "https",
host: "api.github.com",
headers: [
{
header: "content-type",
value: "application/json",
},
],
path: "/graphql",
replyStatus: 200,
requestBody: `{
organization(login: "streamdevs") {
repositories(first: 3, orderBy: {field: STARGAZERS, direction: DESC}) {
nodes {
name
stargazerCount
}
}
}
}`,
responseBody: {
data: {
organization: {
repositories: {
nodes: [
{
name: "webhook",
stargazerCount: 29,
},
{
name: "lights",
stargazerCount: 8,
},
{
name: "platform",
stargazerCount: 5,
},
],
},
},
},
},
});

const subject = new HttpCodeRepositoryRepository();

await subject.getTopRepositories();

asserts.assertEquals(scope.called(), 1);
});
});
21 changes: 21 additions & 0 deletions profile/tests/unit/application/UpdateTopRepositories.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
import { asserts, sinon } from "../../../deps.ts";
import { UpdateTopRepositories } from "../../../src/application/UpdateTopRepositories.ts";

Deno.test("UpdateTopRepositories", async (t) => {
await t.step(
"it calls the CodeRepositoryRepository to get the top 3 repositories",
async () => {
const codeRepositoryRepository = {
getTopRepositories: sinon.spy(() => Promise.resolve([])),
};
const subject = new UpdateTopRepositories(codeRepositoryRepository);

await subject.execute();

asserts.assertEquals(
codeRepositoryRepository.getTopRepositories.called,
true
);
}
);
});
6 changes: 0 additions & 6 deletions profile/tests/url.test.ts

This file was deleted.