Actually leave it to refresh on test, just make sure we dont overwrite

This commit is contained in:
shamoon 2024-10-05 11:52:04 -07:00
parent a4fd5fa7f5
commit 2b1087d837
6 changed files with 13 additions and 46 deletions

View File

@ -11,7 +11,7 @@ import {
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { NgSelectModule } from '@ng-select/ng-select'
import { IMAPSecurity } from 'src/app/data/mail-account'
import { IMAPSecurity, MailAccountType } from 'src/app/data/mail-account'
import { IfOwnerDirective } from 'src/app/directives/if-owner.directive'
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
import { SettingsService } from 'src/app/services/settings.service'
@ -82,6 +82,7 @@ describe('MailAccountEditDialogComponent', () => {
imap_port: 443,
imap_security: IMAPSecurity.SSL,
is_token: false,
account_type: MailAccountType.IMAP,
}
// success

View File

@ -4,7 +4,7 @@ import { TestBed } from '@angular/core/testing'
import { environment } from 'src/environments/environment'
import { commonAbstractPaperlessServiceTests } from './abstract-paperless-service.spec'
import { MailAccountService } from './mail-account.service'
import { IMAPSecurity } from 'src/app/data/mail-account'
import { IMAPSecurity, MailAccountType } from 'src/app/data/mail-account'
let httpTestingController: HttpTestingController
let service: MailAccountService
@ -20,6 +20,7 @@ const mail_accounts = [
username: 'user',
password: 'pass',
is_token: false,
account_type: MailAccountType.IMAP,
},
{
name: 'Mail Account 2',
@ -30,6 +31,7 @@ const mail_accounts = [
username: 'user',
password: 'pass',
is_token: false,
account_type: MailAccountType.IMAP,
},
{
name: 'Mail Account 3',
@ -40,6 +42,7 @@ const mail_accounts = [
username: 'user',
password: 'pass',
is_token: false,
account_type: MailAccountType.IMAP,
},
]
@ -55,20 +58,6 @@ describe(`Additional service tests for MailAccountService`, () => {
expect(req.request.method).toEqual('POST')
})
it('should support patchMany', () => {
subscription = service.patchMany(mail_accounts).subscribe()
mail_accounts.forEach((mail_account) => {
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${mail_account.id}/`
)
expect(req.request.method).toEqual('PATCH')
req.flush(mail_account)
})
httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
)
})
it('should support reload', () => {
service['reload']()
const req = httpTestingController.expectOne(

View File

@ -1,6 +1,5 @@
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { combineLatest, Observable } from 'rxjs'
import { tap } from 'rxjs/operators'
import { MailAccount } from 'src/app/data/mail-account'
import { AbstractPaperlessService } from './abstract-paperless-service'
@ -34,15 +33,12 @@ export class MailAccountService extends AbstractPaperlessService<MailAccount> {
}
update(o: MailAccount) {
// Remove refresh_token and expiration from the object before updating
delete o.refresh_token
delete o.expiration
return super.update(o).pipe(tap(() => this.reload()))
}
patchMany(objects: MailAccount[]): Observable<MailAccount[]> {
return combineLatest(objects.map((o) => super.patch(o))).pipe(
tap(() => this.reload())
)
}
delete(o: MailAccount) {
return super.delete(o).pipe(tap(() => this.reload()))
}

View File

@ -76,21 +76,6 @@ const mail_rules = [
commonAbstractPaperlessServiceTests(endpoint, MailRuleService)
describe(`Additional service tests for MailRuleService`, () => {
it('should support patchMany', () => {
subscription = service.patchMany(mail_rules).subscribe()
mail_rules.forEach((mail_rule) => {
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${mail_rule.id}/`
)
expect(req.request.method).toEqual('PATCH')
req.flush(mail_rule)
})
const reloadReq = httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
)
reloadReq.flush({ results: mail_rules })
})
it('should support reload', () => {
service['reload']()
const req = httpTestingController.expectOne(

View File

@ -37,12 +37,6 @@ export class MailRuleService extends AbstractPaperlessService<MailRule> {
return super.update(o).pipe(tap(() => this.reload()))
}
patchMany(objects: MailRule[]): Observable<MailRule[]> {
return combineLatest(objects.map((o) => super.patch(o))).pipe(
tap(() => this.reload())
)
}
delete(o: MailRule) {
return super.delete(o).pipe(tap(() => this.reload()))
}

View File

@ -80,8 +80,10 @@ class MailAccountTestView(GenericAPIView):
and account.expiration is not None
and account.expiration < timezone.now()
):
if refresh_oauth_token(account):
account.refresh_from_db()
if refresh_oauth_token(existing_account):
# User is not changing password and token needs to be refreshed
existing_account.refresh_from_db()
account.password = existing_account.password
else:
raise MailError("Unable to refresh oauth token")