Skip to content

Commit

Permalink
Feat/buttons (#585)
Browse files Browse the repository at this point in the history
* feat(reviewrequestservice): add initial impl to copute url

* chore(errors): add many errors

* feat(types): add types

* refactor(deployment): chaneg string type to permalink

* feat(pageservice): add new pageservice abstration for raw js wrappers

* feat(json): add new safeJsonParse util

* refactor(reviewrequestservice): refactor to use new page service

* refactor(sitesservice): refactor to use new page service

* refactor(review): refactor for neverthrow api

* chore(server): init page service

* chore(pageservice): add comment

* fix(reviewrequestservice): add in await

* fix(collaboratorsservice): add in unwrap

* chore(review.ts): removed vapt fixes

* chore(services/types): renamed variables and methods for clarity

* chore(errors): removed unneeded properties

* fix(server): u9pdate after rebase

* fix(review): update after rebase

* fix(rebase fixes): add cast cos the `permalink` property is guaranteed but it's opaque atm

* chore(server): add code for init of pageservice

* chore(rr service): specify return types

* fix(notif handler): update to fit new api

* test(app): updated specs to fit with new API   (#587)

* fix(sites.spec): update imports

* test(sitesservice): update types

* test(reviewrequestservice.spec): update spce

* test(collaboratorsservice): fixed tests

* chore(databaseerror): add new error

* fix(sitesservice): fixed regression in code

* test(sitesservice.spec): fixed tests

* chore(sitesservice): remove extra console log

* chore(sites/user spec): add sync to prevent db clash

* chore(databaseerror): removed extra properties

* chore(constants): add new constant for homepage name

* fix(pageservice): fixed bug allowing empty collections

* chore(constants): add new constant for contact-us

* refactor(pages): rename property

* test(pageservice.spec): add tests

* chore(constants): rename homepage constants for consistency

* chore(pageservice): remove redundant code

* chore(pageservice.spec,): remove extra async

* chore(pageservice.spec): standardise imports

\

* refactor(pageservice): update parsecolletionpage

* test(pageservice.spec): update tests for new error mesasge

* fix(pageservice.spec): removed extra newline

* test(integration): fixed reviews integration tests

* test(review): updated spec for new api

* tests(notifs + page): fixed failing tests

* test(review): fix for dev changes
  • Loading branch information
seaerchin authored and alexanderleegs committed Apr 11, 2023
1 parent f919e0e commit 62edb69
Show file tree
Hide file tree
Showing 41 changed files with 2,635 additions and 697 deletions.
6 changes: 3 additions & 3 deletions src/classes/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
// Constants
const FOOTER_PATH = "footer.yml"
const NAVIGATION_PATH = "navigation.yml"
const HOMEPAGE_INDEX_PATH = "index.md" // Empty string
const { HOMEPAGE_NAME } = require("@root/constants")

const retrieveSettingsFiles = async (
accessToken,
Expand Down Expand Up @@ -42,7 +42,7 @@ const retrieveSettingsFiles = async (

// Retrieve homepage only if flag is set to true
if (shouldRetrieveHomepage) {
fileRetrievalObj.homepage = HomepageFile.read(HOMEPAGE_INDEX_PATH)
fileRetrievalObj.homepage = HomepageFile.read(HOMEPAGE_NAME)
}

const fileContentsArr = await Bluebird.map(
Expand Down Expand Up @@ -233,7 +233,7 @@ class Settings {
const homepageContent = ["---\n", homepageFrontMatter, "---"].join("")
const newHomepageContent = Base64.encode(homepageContent)

await HomepageFile.update(HOMEPAGE_INDEX_PATH, newHomepageContent, sha)
await HomepageFile.update(HOMEPAGE_NAME, newHomepageContent, sha)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./constants"
export * from "./pages"
3 changes: 3 additions & 0 deletions src/constants/pages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const HOMEPAGE_FILENAME = "index.md"

export const CONTACT_US_FILENAME = "contact-us.md"
5 changes: 3 additions & 2 deletions src/database/models/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "sequelize-typescript"

import { Site } from "@database/models/Site"
import { ProdPermalink, StagingPermalink } from "@root/types/pages"

@Table({ tableName: "deployments", paranoid: true })
export class Deployment extends Model {
Expand All @@ -26,13 +27,13 @@ export class Deployment extends Model {
allowNull: false,
type: DataType.TEXT,
})
productionUrl!: string
productionUrl!: ProdPermalink

@Column({
allowNull: false,
type: DataType.TEXT,
})
stagingUrl!: string
stagingUrl!: StagingPermalink

@CreatedAt
createdAt!: Date
Expand Down
7 changes: 7 additions & 0 deletions src/errors/DatabaseError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseIsomerError } from "./BaseError"

export default class DatabaseError extends BaseIsomerError {
constructor(message = "Unable to retrieve data from database") {
super(500, message)
}
}
9 changes: 9 additions & 0 deletions src/errors/EmptyStringError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BaseIsomerError } from "./BaseError"

export default class EmptyStringError extends BaseIsomerError {
constructor(
message = "An empty string was provided for a method that requires a non-empty string"
) {
super(500, message)
}
}
7 changes: 7 additions & 0 deletions src/errors/MissingResourceRoomError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NotFoundError } from "./NotFoundError"

export default class MissingResourceRoomError extends NotFoundError {
constructor(message = "No resource room exists for the site") {
super(message)
}
}
7 changes: 7 additions & 0 deletions src/errors/MissingSiteError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NotFoundError } from "./NotFoundError"

export default class MissingSiteError extends NotFoundError {
constructor(message = "The site could not be found in Isomer") {
super(message)
}
}
7 changes: 7 additions & 0 deletions src/errors/MissingUserEmailError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NotFoundError } from "./NotFoundError"

export default class MissingUserEmailError extends NotFoundError {
constructor(message = "No email exists for the specified user!") {
super(message)
}
}
7 changes: 7 additions & 0 deletions src/errors/MissingUserError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NotFoundError } from "./NotFoundError"

export default class MissingUserError extends NotFoundError {
constructor(message = "The user could not be found in Isomer") {
super(message)
}
}
5 changes: 1 addition & 4 deletions src/errors/RequestNotFoundError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { NotFoundError } from "./NotFoundError"

export default class RequestNotFoundError extends NotFoundError {
constructor(message = "The specified review request could not be found!") {
super()
Error.captureStackTrace(this, this.constructor)
this.name = this.constructor.name
this.message = message
super(message)
}
}
10 changes: 10 additions & 0 deletions src/fixtures/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,13 @@ export const MOCK_GITHUB_RAWCOMMENT_TWO: RawComment = {
body: JSON.stringify(MOCK_GITHUB_COMMENT_OBJECT_TWO),
created_at: MOCK_GITHUB_COMMIT_DATE_THREE,
}

export const MOCK_PAGE_PERMALINK = "/department/english"

export const MOCK_GITHUB_FRONTMATTER = Buffer.from(
`---
permalink: ${MOCK_PAGE_PERMALINK}
---
`,
"binary"
).toString("base64")
28 changes: 20 additions & 8 deletions src/fixtures/repoInfo.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { ConfigYmlData } from "@root/types/configYml"
import { GitHubRepositoryData } from "@root/types/repoInfo"
import { Brand } from "@root/types/util"

export const MOCK_STAGING_URL_GITHUB = "https://repo-staging.netlify.app"
export const MOCK_STAGING_URL_CONFIGYML =
"https://repo-staging-configyml.netlify.app"
export const MOCK_STAGING_URL_DB = "https://repo-staging-db.netlify.app"
export const MOCK_STAGING_URL_GITHUB: NonNullable<
ConfigYmlData["staging"]
> = Brand.fromString("https://repo-staging.netlify.app")
export const MOCK_STAGING_URL_CONFIGYML: NonNullable<
ConfigYmlData["staging"]
> = Brand.fromString("https://repo-staging-configyml.netlify.app")
export const MOCK_STAGING_URL_DB: NonNullable<
ConfigYmlData["staging"]
> = Brand.fromString("https://repo-staging-db.netlify.app")

export const MOCK_PRODUCTION_URL_GITHUB = "https://repo-prod.netlify.app"
export const MOCK_PRODUCTION_URL_CONFIGYML =
"https://repo-prod-configyml.netlify.app"
export const MOCK_PRODUCTION_URL_DB = "https://repo-prod-db.netlify.app"
export const MOCK_PRODUCTION_URL_GITHUB: NonNullable<
ConfigYmlData["prod"]
> = Brand.fromString("https://repo-prod.netlify.app")
export const MOCK_PRODUCTION_URL_CONFIGYML: NonNullable<
ConfigYmlData["prod"]
> = Brand.fromString("https://repo-prod-configyml.netlify.app")
export const MOCK_PRODUCTION_URL_DB: NonNullable<
ConfigYmlData["prod"]
> = Brand.fromString("https://repo-prod-db.netlify.app")

export const repoInfo: GitHubRepositoryData = {
name: "repo",
Expand Down
2 changes: 1 addition & 1 deletion src/fixtures/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const MOCK_REPO_DBENTRY_TWO: Attributes<Repo> = {
updatedAt: MOCK_SITE_DATE_TWO,
}

export const MOCK_DEPLOYMENT_DBENTRY_ONE: Attributes<Deployment> = {
export const MOCK_DEPLOYMENT_DBENTRY_ONE = {
id: 1,
siteId: MOCK_SITE_ID_ONE,
productionUrl: MOCK_DEPLOYMENT_PROD_URL_ONE,
Expand Down
62 changes: 61 additions & 1 deletion src/integration/NotificationOnEditHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ import {
mockIsomerUserId,
mockSiteName,
} from "@fixtures/sessionData"
import { BaseDirectoryService } from "@root/services/directoryServices/BaseDirectoryService"
import { ResourceRoomDirectoryService } from "@root/services/directoryServices/ResourceRoomDirectoryService"
import { CollectionPageService } from "@root/services/fileServices/MdPageServices/CollectionPageService"
import { ContactUsPageService } from "@root/services/fileServices/MdPageServices/ContactUsPageService"
import { HomepagePageService } from "@root/services/fileServices/MdPageServices/HomepagePageService"
import { PageService } from "@root/services/fileServices/MdPageServices/PageService"
import { ResourcePageService } from "@root/services/fileServices/MdPageServices/ResourcePageService"
import { SubcollectionPageService } from "@root/services/fileServices/MdPageServices/SubcollectionPageService"
import { UnlinkedPageService } from "@root/services/fileServices/MdPageServices/UnlinkedPageService"
import { CollectionYmlService } from "@root/services/fileServices/YmlFileServices/CollectionYmlService"
import { FooterYmlService } from "@root/services/fileServices/YmlFileServices/FooterYmlService"
import { GitHubService } from "@services/db/GitHubService"
import * as ReviewApi from "@services/db/review"
import { ConfigYmlService } from "@services/fileServices/YmlFileServices/ConfigYmlService"
Expand All @@ -41,13 +52,62 @@ const mockGithubService = {
getComments: jest.fn(),
}
const usersService = getUsersService(sequelize)
const footerYmlService = new FooterYmlService({
gitHubService: mockGithubService,
})
const collectionYmlService = new CollectionYmlService({
gitHubService: mockGithubService,
})
const baseDirectoryService = new BaseDirectoryService({
gitHubService: mockGithubService,
})

const contactUsService = new ContactUsPageService({
gitHubService: mockGithubService,
footerYmlService,
})
const collectionPageService = new CollectionPageService({
gitHubService: mockGithubService,
collectionYmlService,
})
const subCollectionPageService = new SubcollectionPageService({
gitHubService: mockGithubService,
collectionYmlService,
})
const homepageService = new HomepagePageService({
gitHubService: mockGithubService,
})
const resourcePageService = new ResourcePageService({
gitHubService: mockGithubService,
})
const unlinkedPageService = new UnlinkedPageService({
gitHubService: mockGithubService,
})
const configYmlService = new ConfigYmlService({
gitHubService: mockGithubService,
})
const resourceRoomDirectoryService = new ResourceRoomDirectoryService({
baseDirectoryService,
configYmlService,
gitHubService: mockGithubService,
})
const pageService = new PageService({
collectionPageService,
contactUsService,
subCollectionPageService,
homepageService,
resourcePageService,
unlinkedPageService,
resourceRoomDirectoryService,
})
const reviewRequestService = new ReviewRequestService(
(mockGithubService as unknown) as typeof ReviewApi,
User,
ReviewRequest,
Reviewer,
ReviewMeta,
ReviewRequestView
ReviewRequestView,
pageService
)
const sitesService = new SitesService({
siteRepository: Site,
Expand Down
50 changes: 47 additions & 3 deletions src/integration/Notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import {
User,
Whitelist,
} from "@database/models"
import { generateRouter, generateRouterForUserWithSite } from "@fixtures/app"
import { generateRouterForUserWithSite } from "@fixtures/app"
import UserSessionData from "@root/classes/UserSessionData"
import UserWithSiteSessionData from "@root/classes/UserWithSiteSessionData"
import {
formatNotification,
highPriorityOldReadNotification,
Expand All @@ -35,7 +34,18 @@ import { NotificationsRouter as _NotificationsRouter } from "@root/routes/v2/aut
import { SitesRouter as _SitesRouter } from "@root/routes/v2/authenticated/sites"
import { genericGitHubAxiosInstance } from "@root/services/api/AxiosInstance"
import { GitHubService } from "@root/services/db/GitHubService"
import { BaseDirectoryService } from "@root/services/directoryServices/BaseDirectoryService"
import { ResourceRoomDirectoryService } from "@root/services/directoryServices/ResourceRoomDirectoryService"
import { CollectionPageService } from "@root/services/fileServices/MdPageServices/CollectionPageService"
import { ContactUsPageService } from "@root/services/fileServices/MdPageServices/ContactUsPageService"
import { HomepagePageService } from "@root/services/fileServices/MdPageServices/HomepagePageService"
import { PageService } from "@root/services/fileServices/MdPageServices/PageService"
import { ResourcePageService } from "@root/services/fileServices/MdPageServices/ResourcePageService"
import { SubcollectionPageService } from "@root/services/fileServices/MdPageServices/SubcollectionPageService"
import { UnlinkedPageService } from "@root/services/fileServices/MdPageServices/UnlinkedPageService"
import { CollectionYmlService } from "@root/services/fileServices/YmlFileServices/CollectionYmlService"
import { ConfigYmlService } from "@root/services/fileServices/YmlFileServices/ConfigYmlService"
import { FooterYmlService } from "@root/services/fileServices/YmlFileServices/FooterYmlService"
import CollaboratorsService from "@root/services/identity/CollaboratorsService"
import SitesService from "@root/services/identity/SitesService"
import ReviewRequestService from "@root/services/review/ReviewRequestService"
Expand All @@ -58,13 +68,47 @@ const gitHubService = new GitHubService({
const identityAuthService = getIdentityAuthService(gitHubService)
const usersService = getUsersService(sequelize)
const configYmlService = new ConfigYmlService({ gitHubService })
const footerYmlService = new FooterYmlService({ gitHubService })
const collectionYmlService = new CollectionYmlService({ gitHubService })
const baseDirectoryService = new BaseDirectoryService({ gitHubService })

const contactUsService = new ContactUsPageService({
gitHubService,
footerYmlService,
})
const collectionPageService = new CollectionPageService({
gitHubService,
collectionYmlService,
})
const subCollectionPageService = new SubcollectionPageService({
gitHubService,
collectionYmlService,
})
const homepageService = new HomepagePageService({ gitHubService })
const resourcePageService = new ResourcePageService({ gitHubService })
const unlinkedPageService = new UnlinkedPageService({ gitHubService })
const resourceRoomDirectoryService = new ResourceRoomDirectoryService({
baseDirectoryService,
configYmlService,
gitHubService,
})
const pageService = new PageService({
collectionPageService,
contactUsService,
subCollectionPageService,
homepageService,
resourcePageService,
unlinkedPageService,
resourceRoomDirectoryService,
})
const reviewRequestService = new ReviewRequestService(
(gitHubService as unknown) as typeof ReviewApi,
User,
ReviewRequest,
Reviewer,
ReviewMeta,
ReviewRequestView
ReviewRequestView,
pageService
)
const sitesService = new SitesService({
siteRepository: Site,
Expand Down
Loading

0 comments on commit 62edb69

Please sign in to comment.