Skip to content

Commit

Permalink
Fix Sentry app version
Browse files Browse the repository at this point in the history
Fixes #154
  • Loading branch information
akdasa committed Feb 18, 2023
2 parents dd609a0 + b6bf476 commit 5373d9d
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 97 deletions.
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { devices } from '@playwright/test'
const config: PlaywrightTestConfig = {
testDir: './tests/e2e',
/* Maximum time one test can run for. */
timeout: 45 * 1000,
timeout: 60 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
Expand Down Expand Up @@ -70,7 +70,7 @@ const config: PlaywrightTestConfig = {
},
},

// /* Test against mobile viewports. */
/* Test against mobile viewports. */
{
name: 'Mobile Chrome',
use: {
Expand Down
10 changes: 6 additions & 4 deletions src/app/Application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InMemoryRepository } from '@akdasa-studios/framework'
import { SyncRepository } from '@akdasa-studios/framework-sync'
import { Application, InboxCard, Repositories, ReviewCard, Verse, VerseStatus } from "@akdasa-studios/shlokas-core"
import { Capacitor } from '@capacitor/core'
import {
Expand All @@ -18,24 +19,25 @@ export async function createShlokasApplication() {

const repositories = new Repositories(
new InMemoryRepository<Verse>(),
// @ts-ignore
new PouchRepository<VerseStatus>(
couchDB,
"verseStatus",
new VerseStatusSerializer(),
new VerseStatusDeserializer()
),
new PouchRepository<InboxCard>(
new SyncRepository(new PouchRepository<InboxCard>(
couchDB,
"inbox",
new InboxCardSerializer(),
new InboxCardDeserializer()
),
new PouchRepository<ReviewCard>(
)),
new SyncRepository(new PouchRepository<ReviewCard>(
couchDB,
"review",
new ReviewCardSerializer(),
new ReviewCardDeserializer()
),
)),
)
return [
new Application(repositories),
Expand Down
2 changes: 2 additions & 0 deletions src/app/decks/inbox/controllers/InboxDeckCardsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ export class InboxDeckCardsController {
if (e instanceof AddVerseToInboxDeck) { await this.addCardsToDeck() }
})
emitter.on('syncCompleted', async () => { await this.addCardsToDeck() })
emitter.on('appOpened', async () => { await this.addCardsToDeck() })
}

/**
* Adds all cards from the inbox deck to the inbox deck.
*/
async addCardsToDeck() {
const cards = await this._app.inboxDeck.cards()
console.log('addCardsToDeck', JSON.stringify(cards))

for (const card of cards) {
const isAlreadyInDeck = this._inboxDeckStore.hasCard(card.id.value)
Expand Down
6 changes: 5 additions & 1 deletion src/app/settings/components/account/AccountPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,19 @@ import { mail } from 'ionicons/icons'
import { computed, inject, ref } from 'vue'
import { storeToRefs } from 'pinia'
import { Emitter } from 'mitt'
import { Application } from '@akdasa-studios/shlokas-core'
import { useAccountStore } from '@/app/settings'
import { couchDB } from '@/app/Application'
import { AuthService } from '@/services/AuthService'
import { AUTH_HOST } from '@/app/Env'
import { Events } from '@/app/Events'
import { createRepositories } from '@/app/utils/sync'
import LogInViaEmailPage from './email/LogInViaEmailPage.vue'
import SignUpViaEmailPage from './email/SignUpViaEmailPage.vue'
const inProgress = ref(false)
const emitter = inject("emitter") as Emitter<Events>
const app = inject("app") as Application
const account = useAccountStore()
const { isAuthenticated, syncHost, token, email } = storeToRefs(account)
const { logOut } = account
Expand All @@ -128,7 +131,8 @@ async function openModal(component: any) {
async function onSync() {
inProgress.value = true
await couchDB.sync(syncHost.value)
const remoteRepos = createRepositories(syncHost.value as string)
await app.sync(remoteRepos)
emitter.emit('syncCompleted')
inProgress.value = false
}
Expand Down
34 changes: 34 additions & 0 deletions src/app/utils/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { InMemoryRepository } from '@akdasa-studios/framework'
import { SyncRepository } from '@akdasa-studios/framework-sync'
import { InboxCard, Repositories, ReviewCard, Verse, VerseStatus } from "@akdasa-studios/shlokas-core"
import {
CouchDB, InboxCardDeserializer,
InboxCardSerializer, PouchRepository, ReviewCardDeserializer,
ReviewCardSerializer, VerseStatusDeserializer, VerseStatusSerializer
} from '@/services/persistence'


export function createRepositories(remote: string) {
const couchDB = new CouchDB(remote)
return new Repositories(
new InMemoryRepository<Verse>(),
new SyncRepository(new PouchRepository<VerseStatus>(
couchDB,
"verseStatus",
new VerseStatusSerializer(),
new VerseStatusDeserializer()
)),
new SyncRepository(new PouchRepository<InboxCard>(
couchDB,
"inbox",
new InboxCardSerializer(),
new InboxCardDeserializer()
)),
new SyncRepository(new PouchRepository<ReviewCard>(
couchDB,
"review",
new ReviewCardSerializer(),
new ReviewCardDeserializer()
)),
)
}
2 changes: 2 additions & 0 deletions src/init/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// stage 0: infrastructure
import { initSentry } from "./stage-0/initSentry"
import { initLogging } from "./stage-0/initLogging"
import { initDeviceStorage } from "./stage-0/initDeviceStorage"
import { initI18n } from "./stage-0/initI18n"
import { initPinia } from "./stage-0/initPinia"
Expand All @@ -17,6 +18,7 @@ import { initSyncTask } from "./stage-1/initSyncTask"


const initStages = [
initLogging,
initSentry,
initDeviceStorage,
initPinia,
Expand Down
15 changes: 15 additions & 0 deletions src/init/stage-0/initLogging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { LogRecord, Logs, LogTransport } from '@akdasa-studios/framework'


class ConsoleLogTransport implements LogTransport {
log(record: LogRecord): void {
console.log(record.context, record.message, JSON.stringify(record.data))
}
}

/**
* Initialize logging system
*/
export async function initLogging() {
Logs.register(new ConsoleLogTransport())
}
13 changes: 9 additions & 4 deletions src/services/persistence/InboxCardSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ export class InboxCardSerializer implements ObjectMapper<InboxCard, any> {
"@type": "inbox",
"verseId": from.verseId.value,
"type": from.type,
"addedAt": from.addedAt
"addedAt": from.addedAt,
"memorizedAt": from.memorizedAt,
"version": from.version,
})
}
}

export class InboxCardDeserializer implements ObjectMapper<any, InboxCard> {
map(from: any): Result<InboxCard, string> {
return Result.ok(new InboxCard(
const card = new InboxCard(
new VerseId(from["verseId"]),
from['type'] as InboxCardType,
new Date(from['addedAt'])
))
new Date(from['addedAt']),
from['memorizedAt'] ? new Date(from['memorizedAt']) : undefined
)
card.version = from['version']
return Result.ok(card)
}
}
14 changes: 10 additions & 4 deletions src/services/persistence/PouchRepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Aggregate, AnyIdentity, Expression, Identity, Operators, Predicate, Query, QueryBuilder, Repository, Result } from '@akdasa-studios/framework'
import { Aggregate, AnyIdentity, Expression, Identity, Operators, Predicate, Query, QueryBuilder, Repository, Result, LogicalOperators } from '@akdasa-studios/framework'
import PouchDB from 'pouchdb'
import PouchdbFind from 'pouchdb-find'
import PouchDBUpsert from 'pouchdb-upsert'
Expand Down Expand Up @@ -127,19 +127,25 @@ class QueryConverter {
}

convert(query: Query<any>): any {
return {
"selector": this._visit(query)
}
return { "selector": this._visit(query) }
}

_visit(query: Query<any>): any {
if (query instanceof Predicate) {
if (query.operator === Operators.Equal && query.value === undefined) {
return { [query.field]: { "$exists": false } }
}

return {
[query.field]: {
[this.operatorsMap[query.operator]] : this.getValue(query.value)
}
}
} else if (query instanceof Expression) {
if (query.operator === LogicalOperators.Not) {
return { "$not": deepMerge({}, ...query.query.map(x => this._visit(x)) ) }
}

return deepMerge(
{},
...query.query.map(x => this._visit(x))
Expand Down
9 changes: 6 additions & 3 deletions src/services/persistence/ReviewCardSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ export class ReviewCardSerializer implements ObjectMapper<ReviewCard, any> {
"verseId": from.verseId.value,
"type": from.type,
"addedAt": from.addedAt,
"dueTo": from.dueTo
"dueTo": from.dueTo,
"version": from.version,
})
}
}

export class ReviewCardDeserializer implements ObjectMapper<any, ReviewCard> {
map(from: any): Result<ReviewCard, string> {
return Result.ok(new ReviewCard(
const ob = new ReviewCard(
new VerseId(from["verseId"]),
from['type'] as ReviewCardType,
new Date(from['addedAt']),
new Date(from['dueTo']),
))
)
ob.version = from['version']
return Result.ok(ob)
}
}
9 changes: 6 additions & 3 deletions src/services/persistence/VerseStatusSerializer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Result } from "@akdasa-studios/framework"
import { Decks, VerseId, VerseStatus, VerseStatusId } from "@akdasa-studios/shlokas-core"
import { Decks, VerseId, VerseStatus } from "@akdasa-studios/shlokas-core"
import { ObjectMapper } from "./ObjectMapper"


Expand All @@ -10,15 +10,18 @@ export class VerseStatusSerializer implements ObjectMapper<VerseStatus, any> {
"@type": "verseStatus",
"verseId": from.verseId.value,
"inDeck": from.inDeck,
"version": from.version,
})
}
}

export class VerseStatusDeserializer implements ObjectMapper<any, VerseStatus> {
map(from: any): Result<VerseStatus, string> {
return Result.ok(new VerseStatus(
const ob = new VerseStatus(
new VerseId(from["verseId"]),
from['inDeck'] as Decks
))
)
ob.version = from['version']
return Result.ok(ob)
}
}
11 changes: 9 additions & 2 deletions tests/e2e/scenarios/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function signUp(
appPage: Page,
email: string
) {
const account = new Account(appPage)
const account = new Account(appPage)

// act
await account.open()
Expand All @@ -20,8 +20,15 @@ export async function signUp(
const mailPage = await context.newPage()
await mailPage.goto('http://localhost:1080/')
await mailPage.getByRole('cell', { name: `<${email}>` }).first().click()

await mailPage.frameLocator('iframe').getByRole('link', { name: 'Confirm email' }).click()
// await mailPage.frameLocator('iframe').getByText('Email has been confirmed!').waitFor()
await mailPage.waitForTimeout(4000) // code below doesn't work for some reason
await mailPage.close()
// const [popup] = await Promise.all([
// mailPage.waitForEvent('popup'),
// mailPage.frameLocator('iframe').getByRole('link', { name: 'Confirm email' }).click()
// ])
// popup.getByText('Email has been confirmed!').waitFor()
}

export async function logIn(
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/settings/Registration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test.describe('Settings › Account › Email', () => {
const [context2, page2] = await logInNewDevice(browser, email)
await expect(page2.getByText("Welcome back!")).toBeVisible()

page2.close()
context2.close()
await page2.close()
await context2.close()
})
})
Loading

0 comments on commit 5373d9d

Please sign in to comment.