Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/build_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
with:
cache-mode: 'read-only'
ref: ${{ github.event.pull_request.head.sha }}
angular-versions: '^21'
secrets:
NX_KEY: ${{ secrets.NX_KEY }}
AZURE_STORAGE_CONNECTION_STRING: ${{ github.event.pull_request.head.repo.full_name == github.repository && secrets.AZURE_NX_CACHE_READWRITE_CONNECTION_STRING || secrets.AZURE_NX_CACHE_READONLY_CONNECTION_STRING }}
Expand Down
3 changes: 2 additions & 1 deletion apps/daffio/src/main.server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { provideZoneChangeDetection } from '@angular/core';
import {
BootstrapContext,
bootstrapApplication,
Expand All @@ -7,6 +8,6 @@ import { DaffioAppComponent } from './app/app.component';
import { config } from './app/app.config.server';

const bootstrap = (context: BootstrapContext) =>
bootstrapApplication(DaffioAppComponent, config, context);
bootstrapApplication(DaffioAppComponent, { ...config, providers: [provideZoneChangeDetection(), ...config.providers]}, context);

export default bootstrap;
27 changes: 22 additions & 5 deletions apps/daffio/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files


// eslint-disable-next-line import/no-unassigned-import
import 'zone.js';
// eslint-disable-next-line import/no-unassigned-import
import 'zone.js/testing';
import {
NgModule,
provideZoneChangeDetection,
} from '@angular/core';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
BrowserTestingModule,
platformBrowserTesting,
} from '@angular/platform-browser/testing';

@NgModule({
providers: [
provideZoneChangeDetection(),
],
})
class ExpressionChangedAfterCheckedWorkaround {}

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting(),
[
BrowserTestingModule,
ExpressionChangedAfterCheckedWorkaround,
],
platformBrowserTesting(),
);
7 changes: 5 additions & 2 deletions apps/demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { enableProdMode } from '@angular/core';
import {
enableProdMode,
provideZoneChangeDetection,
} from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { DemoModule } from './app/app.module';
Expand All @@ -9,5 +12,5 @@ if (environment.production) {
}

platformBrowserDynamic()
.bootstrapModule(DemoModule)
.bootstrapModule(DemoModule, { applicationProviders: [provideZoneChangeDetection()]})
.catch(err => console.error(err));
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { TestBed } from '@angular/core/testing';
import {
DocumentNode,
gql,
NextLink,
Operation,
} from '@apollo/client/core';
ApolloLink,
} from '@apollo/client';
import { Apollo } from 'apollo-angular';
import {
ApolloTestingController,
Expand All @@ -18,7 +17,7 @@ import { MagentoAuthApolloBearerTokenLinkGenerator } from './apollo-bearer-token
describe('@daffodil/auth/driver/magento | MagentoAuthApolloBearerTokenLinkGenerator', () => {
let service: MagentoAuthApolloBearerTokenLinkGenerator;
let daffAuthStorageService: jasmine.SpyObj<DaffAuthStorageService>;
let operation: Operation;
let operation: ApolloLink.Operation;
let apollo: Apollo;
let controller: ApolloTestingController;

Expand Down Expand Up @@ -62,9 +61,9 @@ describe('@daffodil/auth/driver/magento | MagentoAuthApolloBearerTokenLinkGenera
it('should set the authorization header to the bearer token', () => {
apollo.query({ query }).subscribe();
operation = controller.expectOne(query).operation;
service.getLink().request(operation, <NextLink><unknown>jasmine.createSpy);
service.getLink().request(operation, <ApolloLink.ForwardFunction><unknown>jasmine.createSpy);

expect(operation.getContext().headers.authorization).toEqual(`Bearer ${token}`);
expect(operation.getContext().headers?.get('authorization')).toEqual(`Bearer ${token}`);
});
});

Expand All @@ -76,9 +75,9 @@ describe('@daffodil/auth/driver/magento | MagentoAuthApolloBearerTokenLinkGenera
it('should not set the authorization header', () => {
apollo.query({ query }).subscribe();
operation = controller.expectOne(query).operation;
service.getLink().request(operation, <NextLink><unknown>jasmine.createSpy);
service.getLink().request(operation, <ApolloLink.ForwardFunction><unknown>jasmine.createSpy);

expect(operation.getContext().headers?.authorization).toBeUndefined();
expect(operation.getContext().headers?.get('authorization')).toBeUndefined();
});
});

Expand All @@ -90,9 +89,9 @@ describe('@daffodil/auth/driver/magento | MagentoAuthApolloBearerTokenLinkGenera
it('should not crash', () => {
apollo.query({ query }).subscribe();
operation = controller.expectOne(query).operation;
service.getLink().request(operation, <NextLink><unknown>jasmine.createSpy);
service.getLink().request(operation, <ApolloLink.ForwardFunction><unknown>jasmine.createSpy);

expect(operation.getContext().headers?.authorization).toBeUndefined();
expect(operation.getContext().headers?.get('authorization')).toBeUndefined();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import {
Injectable,
makeEnvironmentProviders,
} from '@angular/core';
import { ApolloLink } from '@apollo/client/core';
import { ApolloLink } from '@apollo/client';

import { DaffAuthStorageService } from '@daffodil/auth';
import {
DaffApolloLinkGenerator,
getApolloOperationHeaders,
provideDaffApolloHeaderProviders,
} from '@daffodil/core/graphql';
import {
Expand Down Expand Up @@ -63,10 +64,7 @@ export class MagentoAuthApolloBearerTokenLinkGenerator implements DaffApolloLink

if (token) {
operation.setContext({
headers: {
...operation.getContext().headers,
authorization: `Bearer ${token}`,
},
headers: getApolloOperationHeaders(operation).append('authorization', `Bearer ${token}`),
});
}
return forward(operation);
Expand Down
11 changes: 7 additions & 4 deletions libs/auth/driver/magento/src/errors/transform.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ApolloError } from '@apollo/client/core';

import { CombinedGraphQLErrors } from '@apollo/client';

import { DaffUnauthorizedError } from '@daffodil/auth/driver';

import { MagentoAuthGraphQlErrorCode } from './codes';
import { transformMagentoAuthError } from './transform';


describe('@daffodil/auth/driver/magento | transformMagentoAuthError', () => {
const unhandledGraphQlError = {
message: 'A error we dont handle',
Expand All @@ -31,9 +33,10 @@ describe('@daffodil/auth/driver/magento | transformMagentoAuthError', () => {
};

it('should be able to process graphql errors and return the relevant DaffAuth error if a mapping exists', () => {
const error = new ApolloError({
graphQLErrors: [handledGraphQlError],
});
const error = new CombinedGraphQLErrors(
{},
[handledGraphQlError],
);
const result = transformMagentoAuthError(error);

expect(result).toEqual(jasmine.any(DaffUnauthorizedError));
Expand Down
6 changes: 2 additions & 4 deletions libs/auth/driver/magento/src/validators/check-token.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';
import { MagentoCheckTokenResponse } from '@daffodil/auth/driver/magento';

import { validateCheckTokenResponse as validator } from './check-token';

describe('@daffodil/auth/driver/magento | validateCheckTokenResponse', () => {
let response: ApolloQueryResult<MagentoCheckTokenResponse>;
let response: Apollo.QueryResult<MagentoCheckTokenResponse>;

beforeEach(() => {
response = {
Expand All @@ -15,8 +15,6 @@ describe('@daffodil/auth/driver/magento | validateCheckTokenResponse', () => {
email: 'email',
},
},
loading: null,
networkStatus: null,
};
});

Expand Down
4 changes: 2 additions & 2 deletions libs/auth/driver/magento/src/validators/check-token.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';

import { MagentoCheckTokenResponse } from '../queries/public_api';

export const validateCheckTokenResponse = (response: ApolloQueryResult<MagentoCheckTokenResponse>) => {
export const validateCheckTokenResponse = (response: Apollo.QueryResult<MagentoCheckTokenResponse>) => {
if (response.data.customer.email) {
return response;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';
import { MagentoGenerateTokenResponse } from '@daffodil/auth/driver/magento';

import { validateGenerateTokenResponse as validator } from './generate-token';

describe('@daffodil/auth/driver/magento | GenerateToken', () => {
let response: ApolloQueryResult<MagentoGenerateTokenResponse>;
let response: Apollo.QueryResult<MagentoGenerateTokenResponse>;

beforeEach(() => {
response = {
Expand All @@ -15,8 +15,6 @@ describe('@daffodil/auth/driver/magento | GenerateToken', () => {
token: 'token',
},
},
loading: null,
networkStatus: null,
};
});

Expand Down
4 changes: 2 additions & 2 deletions libs/auth/driver/magento/src/validators/generate-token.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';

import { MagentoGenerateTokenResponse } from '../queries/public_api';

export const validateGenerateTokenResponse = (response: ApolloQueryResult<MagentoGenerateTokenResponse>) => {
export const validateGenerateTokenResponse = (response: Apollo.QueryResult<MagentoGenerateTokenResponse>) => {
if (response.data.generateCustomerToken.token) {
return response;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';
import { MagentoResetPasswordResponse } from '@daffodil/auth/driver/magento';

import { validateResetPasswordResponse as validator } from './reset-password';

describe('@daffodil/auth/driver/magento | validateResetPasswordResponse', () => {
let response: ApolloQueryResult<MagentoResetPasswordResponse>;
let response: Apollo.QueryResult<MagentoResetPasswordResponse>;

beforeEach(() => {
response = {
data: {
resetPassword: true,
},
loading: null,
networkStatus: null,
};
});

Expand Down
4 changes: 2 additions & 2 deletions libs/auth/driver/magento/src/validators/reset-password.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';

import { MagentoResetPasswordResponse } from '../models/public_api';

export const validateResetPasswordResponse = (response: ApolloQueryResult<MagentoResetPasswordResponse>) => {
export const validateResetPasswordResponse = (response: Apollo.QueryResult<MagentoResetPasswordResponse>) => {
if (response.data.resetPassword) {
return response;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';
import { MagentoRevokeCustomerTokenResponse } from '@daffodil/auth/driver/magento';

import { validateRevokeTokenResponse as validator } from './revoke-token';

describe('@daffodil/auth/driver/magento | RevokeToken', () => {
let response: ApolloQueryResult<MagentoRevokeCustomerTokenResponse>;
let response: Apollo.QueryResult<MagentoRevokeCustomerTokenResponse>;

beforeEach(() => {
response = {
Expand All @@ -15,8 +15,6 @@ describe('@daffodil/auth/driver/magento | RevokeToken', () => {
result: true,
},
},
loading: null,
networkStatus: null,
};
});

Expand Down
4 changes: 2 additions & 2 deletions libs/auth/driver/magento/src/validators/revoke-token.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';

import { MagentoRevokeCustomerTokenResponse } from '../queries/public_api';

export const validateRevokeTokenResponse = (response: ApolloQueryResult<MagentoRevokeCustomerTokenResponse>) => {
export const validateRevokeTokenResponse = (response: Apollo.QueryResult<MagentoRevokeCustomerTokenResponse>) => {
if (response.data.revokeCustomerToken.result) {
return response;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';
import { MagentoSendResetEmailResponse } from '@daffodil/auth/driver/magento';

import { validateSendResetEmailResponse as validator } from './send-reset-email';

describe('@daffodil/auth/driver/magento | validateSendResetEmailResponse', () => {
let response: ApolloQueryResult<MagentoSendResetEmailResponse>;
let response: Apollo.QueryResult<MagentoSendResetEmailResponse>;

beforeEach(() => {
response = {
data: {
requestPasswordResetEmail: true,
},
loading: null,
networkStatus: null,
};
});

Expand Down
4 changes: 2 additions & 2 deletions libs/auth/driver/magento/src/validators/send-reset-email.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApolloQueryResult } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';

import { DaffAuthInvalidAPIResponseError } from '@daffodil/auth/driver';

import { MagentoSendResetEmailResponse } from '../models/public_api';

export const validateSendResetEmailResponse = (response: ApolloQueryResult<MagentoSendResetEmailResponse>) => {
export const validateSendResetEmailResponse = (response: Apollo.QueryResult<MagentoSendResetEmailResponse>) => {
if (response.data.requestPasswordResetEmail) {
return response;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing';
import { InMemoryCache } from '@apollo/client/core';
import { InMemoryCache } from '@apollo/client';
import { addTypenameToDocument } from '@apollo/client/utilities';
import {
ApolloTestingController,
Expand Down Expand Up @@ -78,7 +78,6 @@ describe('@daffodil/cart-customer/driver/magento | DaffMagentoCartCustomerServic
{
provide: APOLLO_TESTING_CACHE,
useValue: new InMemoryCache({
addTypename: true,
possibleTypes: schema.possibleTypes,
}),
},
Expand Down
Loading
Loading